File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes  new elements in the arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " new elements in the arraylist" Watch " new elements in the arraylist" New topic
Author

new elements in the arraylist

Anne Saizan
Ranch Hand

Joined: May 07, 2011
Posts: 35
Hello there,
i just wanna ask , how to enter a new elements in the arraylist?
the new element must be the input of the keyboard.
Thank you.
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
you can use add() method of ArrayList class

for example:

Anne Saizan
Ranch Hand

Joined: May 07, 2011
Posts: 35
thanks for the reply.
can we use add() if the user add new elements using keyboard.



here is my code. can i do that for this one?
Anne Saizan
Ranch Hand

Joined: May 07, 2011
Posts: 35
sorry this is my first time using this forum.
hehe
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
please see the link belowhttp://www.java2s.com/Code/Java/Collections-Data-Structure/Storeuserdefinedobjectsinarraylist.htm
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

Hi Anne. Welcome to The Ranch!

The short answer is yes. I haven't checked to see if that specific code works, but once you've created an object it makes no difference where it came from when you're adding it to an ArrayList. If you can get a reference to a Student1 object, you can add it

The best approach, though, when you're faced with a question "can I do this" is to try it out. Write a small program to test it - it's the most effective way to learn. Then, once you know what does happen, you can ask questions about why it happens.

(By the way, you can edit an existing message to fix formatting - you don't need to post another one).
Anne Saizan
Ranch Hand

Joined: May 07, 2011
Posts: 35
oky thank you so much..=)
sorry about the code...
i am still new here..=)
bdw thanks..
nice java forum..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: new elements in the arraylist
 
Similar Threads
Simple ArrayList conundrum?
clone of ArrayList
Generics
ArrayList sorting using Ccomparator
Doubt in generics