Skip to content

Instantly share code, notes, and snippets.

Created Mar 11, 2014
What would you like to do?
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Student {
private String name;
public static Comparator<Student> getCompByName() {
Comparator<Student> comp = new Comparator<Student>() {
public int compare(Student s1, Student s2) {
return comp;
public Student(String name) { = name;
public String getName() {
return name;
public void setName(String name) { = name;
public static void main(String[] args) {
Student[] studentArr = new Student[]{new Student("Mike"),new Student("Hector"), new Student("Reggie"),new Student("zark")};
List<Student> students = new ArrayList<Student>(Arrays.asList(studentArr));
Collections.sort(students, Student.getCompByName());
for(Student student:students){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment