Skip to content

Instantly share code, notes, and snippets.

@happyduck-git
Created June 6, 2022 02:04
Show Gist options
  • Save happyduck-git/aa897ba8cd0a4ac4bceace288e64e099 to your computer and use it in GitHub Desktop.
Save happyduck-git/aa897ba8cd0a4ac4bceace288e64e099 to your computer and use it in GitHub Desktop.
/* 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