• 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

Why should i turn String to String in arrayList ?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey everyone, please lend me help understanding in line 7 why should i turn arr.get(indx) to String, If it already returns String, since get() method of ArrayList returns String of an index, thanks a million .

 
Ranch Hand
Posts: 47
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aladdin Raul,

The ArrayList.get() method, given the index, doesn't return a String but an Object
Here's the link to the docs:
http://download.oracle.com/javase/1.4.2/docs/api/java/util/List.html#get(int)

By calling toString() on that Object you will get a textual representation of the object. Really depends on the object and if it implements the toString method or not.
 
Aladdin Raul
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You bet, thanks
 
Ranch Hand
Posts: 73
Android Netbeans IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Aladdin Raul ,
Ronald Castillo is correct, arr.get returns an Object and label's setText expects a String, so there is a type mismatch. Hence it is necessary to use toString.
I guess you could use generics to your advantage to avoid toString. For instance

would work fine. Give it a try.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic