wood burning stoves*
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 Spring in Action this week in the Spring 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: 775
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: 61420
    
  67

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());
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: converting an array to List