Bookmark Topic Watch Topic
  • New Topic

regarding objects and collections  RSS feed

 
suresh sai
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • 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?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Chinna,
First of all, you've got two same threads at http://www.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.
 
Vijayender Bandaru
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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 ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!