• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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: 76866
366
  • 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.
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic