Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

toString() of Vector  RSS feed

 
Chris Yates
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought i had to write a for loop to go through all of the elements in a Vector but it turns out toString() of Vector already does that. Usually by default they print some weird numbers, references i believe, why is it not the sace with Vector? How could have i guessed this? -.-
 
Stephan van Hulst
Saloon Keeper
Posts: 7812
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It says so in the documentation of Vector.
 
Liutauras Vilda
Marshal
Posts: 4647
318
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris Yates wrote:Usually by default they print some weird numbers, references i believe, why is it not the sace with Vector?

Because Vector class overrides toString in class AbstractCollection<E>. You can find this in Java API documentation (<- link).
And those weird numbers are the object's class name followed by @ and its hashcode, because not all classes overrides toString method. i.e. you have seen it probably with Arrays class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!