import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Test{ public static void main(String[] args) { List<Foo> myFooList = new ArrayList<Foo>(); myFooList.add(new Foo("C")); myFooList.add(new Foo("A")); myFooList.add(new Foo("D")); Collections.sort(myFooList); System.out.print(myFooList.get(0).code); } } class Foo implements Comparable<Foo> { String code; Foo(String c) { code = c; } int compareTo(Foo f) { return this.code.compareTo(f.code); } }
import java.util.Collections;
import java.util.List;
public class Test{
public static void main(String[] args) {
List<Foo> myFooList = new ArrayList<Foo>();
myFooList.add(new Foo("C"));
myFooList.add(new Foo("A"));
myFooList.add(new Foo("D"));
Collections.sort(myFooList);
System.out.print(myFooList.get(0).code);
}
class Foo implements Comparable<Foo> {
String code;
Foo(String c) {
code = c;
int compareTo(Foo f) {
return this.code.compareTo(f.code);
Oracle Certified Professional Java Programmer
Access: Public Instant Grading
Jobilize.com uses cookies to ensure that you get the best experience. By continuing to use Jobilize.com web-site, you agree to the Terms of Use.