Solved

Java Collections Sort

Posted on 2012-04-09
1
514 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
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
replace a word with other 1 44
Groovy problem when using SOAPUI : DispatchException occurred 7 44
table example 4 29
hibernate example for saving data 19 38
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

770 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