Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

new elements in the arraylist

 
Anne Saizan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use add() method of ArrayList class

for example:

 
Anne Saizan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry this is my first time using this forum.
hehe
 
harshada patil
Ranch Hand
Posts: 96
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oky thank you so much..=)
sorry about the code...
i am still new here..=)
bdw thanks..
nice java forum..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic