Solved

Java Collections Sort

Posted on 2012-04-09
1
518 Views
Last Modified: 2012-04-09
How can I sort an ArrayList of objects:

ArrayList<CommandModel> codes;
          
Collections.sort(codes);  ===> Bound Mismatch on compile

CommandModel contains:

                 private String code;

      public String toString() {
            return code;
      }
      
      public int compareTo(Object o1) {                      
            return (this.code.compareTo(((CommandModel) o1).toString()) );    
      }
0
Comment
Question by:va3jsl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
CPColin earned 500 total points
ID: 37825394
Your CommandModel class needs to implement Comparable<CommandModel> for Collections.sort() to work.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
difference between sorce folder and folder in eclipise 3 40
going to wrong jsp page 2 46
Glassfish admin console not working 1 56
Html split(text) 2 27
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

761 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question