how to iterate in List> in java and set their values as we do in a normal int a[i][j] matrix type [duplicate]

I think what you’re asking is how to do this: List<List<Int>> arrayList = new ArrayList(); //Java usually infers type parameters in cases as these for(int i = 0; i < desiredSize; i++){ List<Int> listAtI = new ArrayList (); for(int j = 0; j < rowLength; j++){ listAtI.set(j, 0); //sets the element at j to be … Read more

java Arrays.sort 2d array

Use Overloaded Arrays#Sort(T[] a, Comparator c) which takes Comparator as the second argument. double[][] array= { {1, 5}, {13, 1.55}, {12, 100.6}, {12.1, .85} }; java.util.Arrays.sort(array, new java.util.Comparator<double[]>() { public int compare(double[] a, double[] b) { return Double.compare(a[0], b[0]); } }); JAVA-8: Instead of that big comparator, we can use lambda function as following- Arrays.sort(array, Comparator.comparingDouble(o -> o[0]));