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

regarding objects and collections

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
hi,
the following code gives ClassCastException.

Object [] myObjects={new String("foo"),new Boolean(true),new Integer(5)};
Arrays.sort(myobjects);

Is it because of ,myObjects contain different type of objects or it is due to..Object is super class of Arrays.Please tellme ,How can I rectify the error?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Chinna,
First of all, you've got two same threads at https://coderanch.com/forums/f-33/java .
You can remove one of them by selecting it, clicking the edit icon of your post (here), checking the "Delete Post" checkbox and confirming.

Secondly, it's not cool to post the same question in different threads. Could you please continue in your original post ? Thank you.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
That was obvious because all elements in the array were not mutually comparable.Read more at:

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Arrays.html

http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html
[ August 07, 2007: Message edited by: Vijayender R. Bandaru ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please don't post the same question in multiple forums. It creates duplicate conversations and wastes the time of the people trying to help you.

Thanks,
Dave
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic