Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how do I print the elements in the Arraylist without the null.

 
sharon avitan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am want to print this arraylist with out the null.
i


this is what I get:
The array is:
arr[0] = Papa Bill
arr[1] = Ali Baba
arr[2] = Ming the Merciless
arr[3] = Grandpa
arr[4] = Tornado
arr[5] = null

I also tried doing this with a toString().



in this I get NullPointerException..

[Edit: added code tags - MB]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12344
39
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in other words...



(that is a hint...)
 
Campbell Ritchie
Marshal
Posts: 52664
122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no need to call toString() on the object you are printing. If you try this sort of thingYou will get whatever the toString method in the Foo class returns. You won't get any Exceptions, not even if you try to print null, as explained here (and here).
 
sharon avitan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It worked ..
Thank You
 
sharon avitan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the element is not null ... print
worked for me
thanks...
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!