Created
July 13, 2014 18:53
-
-
Save pnuz3n/85761528fdef66d10609 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| import java.util.Comparator; | |
| public class Main { | |
| public static void main(String[] args) { | |
| String Name[][] = { | |
| {"prakash", "kumar"}, | |
| {"raj", "kappor"}, | |
| {"vinod", "bhart"}, | |
| {"yraj", "tkappor"}, | |
| {"avinod", "fbhart"} | |
| }; | |
| Arrays.sort(Name, new Comparator<String[]>() { | |
| int LASTNAME = 0, FIRSTNAME = 1; | |
| @Override | |
| public int compare(String[] o1, String[] o2) { | |
| int c = o1[LASTNAME].compareTo(o2[LASTNAME]); | |
| if (c != 0) return c; | |
| return o1[FIRSTNAME].compareTo(o2[FIRSTNAME]); | |
| } | |
| }); | |
| for (String[] n : Name) { | |
| System.out.println(n[0] + "," + n[1]); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment