Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

converting an array to List

 
jyothi dandamudi
Greenhorn
Posts: 4
  • 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: 1328
6
  • 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: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
  • 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());
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic