Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to create an ArrayList

 
Emanuel Mensa
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

i need some help.

i want to create a class that has a constructor to create an arraylist. then i want to create another MAIN class that will create new arraylist objects. how can i do this?
i tried something but i'm getting compile errors.

for instance i wanted to create a class like this



my main class



but the problem here is, i want the contructor to create an array list that will take an argument of how the Arraylist<String> is to be named.

i know this is simple, but i forgot how to do this somehow. please help me out

thanks.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Emanuel Mensa wrote:
i tried something but i'm getting compile errors.


For people to be able to help you, you need to show what you tried, as well as copy/pasting the exact complete error message into your post, and indicating clearly which line caused it.
 
Emanuel Mensa
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Emanuel Mensa wrote:
i tried something but i'm getting compile errors.


For people to be able to help you, you need to show what you tried, as well as copy/pasting the exact complete error message into your post, and indicating clearly which line caused it.


i edited my post.
i just want to create new objects of Names class and maybe passing in arguments that will be names of the ArrayList.

i hope it's clear now what i want to achieve

thanks.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Emanuel Mensa wrote:
i hope it's clear now what i want to achieve


I'm not sure, but it's definitely not clear what problem you're having.
 
Emanuel Mensa
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i want to create a contructor that will take as a parameter a name for an arraylist. now i made it simpler.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Emanuel Mensa wrote:ok i want to create a contructor that will take as a parameter a name for an arraylist. now i made it simpler.


Okay, but what do you mean a "name for an ArrrayList"? Objects don't have names, so are you defining some class that will contain an ArrayList field and a name field, so that you can associate that name with that list?



Or perhaps you're thinking of passing in a variable that refers to an ArrayList? Note that a variable is not an object's name. Objects don't have names.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic