Created
June 6, 2022 02:04
-
-
Save happyduck-git/aa897ba8cd0a4ac4bceace288e64e099 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
/* 1D나 2D array 모두에 사용 가능!*/ | |
int[][] ints = new int[n][2]; | |
for(int i = 0; i < n; i++) { | |
st = new StringTokenizer(br.readLine()); | |
ints[i][0] = Integer.parseInt(st.nextToken()); | |
ints[i][1] = Integer.parseInt(st.nextToken()); | |
} | |
//***int[][]경우에 이렇게 comparator 사용 가능!*** | |
Arrays.sort(ints, new Comparator<int[]>() { | |
@Override | |
public int compare(int[] o1, int[] o2) { | |
if(o1[0]- o2[0] == 0) { | |
return Integer.compare(o1[1], o2[1]); | |
} | |
return Integer.compare(o1[0], o2[0]); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment