| 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: 94
|
|
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: 94
|
|
|
please see the link belowhttp://www.java2s.com/Code/Java/Collections-Data-Structure/Storeuserdefinedobjectsinarraylist.htm
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3786
|
|
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..
|
 |
 |
|
|
subject: new elements in the arraylist
|
|
|