• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to print all element of List over console?

 
Ranch Hand
Posts: 74
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a list collection which having some element and i want to check it that which element it has....please reply me.
thanks!
 
Ranch Hand
Posts: 157
1
Android MySQL Database Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vivek, you can simply sysout list object.
 
viki Bhardwaj
Ranch Hand
Posts: 74
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks! Harsh,
but when i trying to do as you said then it prints className@Hashcode(Maintenance@j1296)
here i have a following code like that..

cList=(List)request.getAttribute("maintObj");

now i want to check the data contains by List cList and wanna see entire data contained by the cList...
how should i do???
 
harshvardhan ojha
Ranch Hand
Posts: 157
1
Android MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Vivek, you have kept objects of Maintenance class inside list. Please override toString() in Maintenance class and everything should be fine. Hope this is helpful.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

harshvardhan ojha wrote: . . . Hope this is helpful.

Yes, it is

But I would suggest, maybe, you might possibly like to give a little more explanation and describe the behaviour of toString a bit more.
 
harshvardhan ojha
Ranch Hand
Posts: 157
1
Android MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why not Campbell,

We override toString() method from Object class to give meaningful String representation of the Object.
Say your class is



My output is : Maintainance@767946a2

This is class name+'@'+hex version of the object hashcode. This doesn't make any sense

lets say i want to understand more about my object i will override this toString() method to this class



My output will be : Maintainance [name=Harshvardhan, age=25]

And this info makes sense. So its always good to have toString(). Similarly please read on equals() and hashcode() also.
I hope this will be helpful.

Thanks Campbell for figuring it out, i always make assumptions like this.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic