• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding item to arraylist  RSS feed

 
Venu Adhikesevan
Greenhorn
Posts: 3
Eclipse IDE Firefox Browser Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys I'm new to java, Please help me to understand the below logic

Creating an Arraylist and adding item to that array, refer below code



Both adds the String item to array list but puzzling what makes the difference....

Appreciate your time Thanks!!!
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Venu Adhikesevan wrote:Both adds the String item to array list but puzzling what makes the difference....

It really has nothing to do with ArrayList, and everything to do with how you create your String.

For more information, have a look at the CachedObjects page, but either will work just fine. The second version of your code is better though.

HIH

Winston
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I added code tags to your post and doesn't it look better. Always use the tags for code.
I don't understand the question. I cannot see any difference between the two add calls. Add this line at the end of your code and see what happens:-
System.out.println(sjarr);

By the way: Lines 03 and 07 should really not be there. They constitute labels, which are out of place, and will prevent correct compilation.
 
Venu Adhikesevan
Greenhorn
Posts: 3
Eclipse IDE Firefox Browser Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply guys....
Thanks for Formatting will take care here after
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!