This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes how do I print the elements in the Arraylist without the null. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "how do I print the elements in the Arraylist without the null." Watch "how do I print the elements in the Arraylist without the null." New topic
Author

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

sharon avitan
Greenhorn

Joined: Sep 14, 2011
Posts: 3
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

Joined: Oct 02, 2003
Posts: 9952
    
    6

in other words...



(that is a hint...)


Never ascribe to malice that which can be adequately explained by stupidity.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
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

Joined: Sep 14, 2011
Posts: 3
It worked ..
Thank You
sharon avitan
Greenhorn

Joined: Sep 14, 2011
Posts: 3
if the element is not null ... print
worked for me
thanks...
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: how do I print the elements in the Arraylist without the null.
 
Similar Threads
Why it is not 'null' ?
Mock Exam Q
Three dim array
Reading arrays
Why I get the List content when I print the List object?