Solved

Java Collections Sort

Posted on 2012-04-09
1
512 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
Comment Utility
Your CommandModel class needs to implement Comparable<CommandModel> for Collections.sort() to work.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now