This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

converting an array to List

 
jyothi dandamudi
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i am getting error at line 44 when i was trying to convert the Object[] ob array to back to List<Dog> even though i was casting the object array back to Dog.
please let me know where i was going wrong.
 
Himai Minh
Ranch Hand
Posts: 1142
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you type cast a List into a Dog.
Can you type cast a List into a String / an Integer / a Double ? No.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this is real-world code, you're reinventing the wheel. See the asList() method of java.util.Arrays

 
jyothi dandamudi
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Himai Minh, sometimes my mind gets blocked.

i replaced the lines 44 and 45 with the following lines and it worked. i just want to print the size of the list after removing element from it.

List a = Arrays.asList(ob);
System.out.println("The size of the list after removing one element is" + a.size());
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic