Two Laptop Bag*
The moose likes Beginning Java and the fly likes how to create an ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to create an ArrayList" Watch "how to create an ArrayList" New topic
Author

how to create an ArrayList

Emanuel Mensa
Ranch Hand

Joined: Feb 22, 2013
Posts: 31
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Feb 22, 2013
Posts: 31
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Feb 22, 2013
Posts: 31
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to create an ArrayList
 
Similar Threads
ArrayList, contains, objects
How to maintain order in list
Returning ArrayList from Method
extending an arraylist\hashmap
Questions of how access methods of other class.