wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes converting an array to List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "converting an array to List" Watch "converting an array to List" New topic
Author

converting an array to List

jyothi dandamudi
Greenhorn

Joined: May 11, 2011
Posts: 4


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

Joined: Jul 29, 2012
Posts: 736
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

Joined: Jan 10, 2002
Posts: 61066
    
  66

If this is real-world code, you're reinventing the wheel. See the asList() method of java.util.Arrays


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jyothi dandamudi
Greenhorn

Joined: May 11, 2011
Posts: 4
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());
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: converting an array to List