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  0, notice the values are Int not int, this is dues to Javas generics having to work with classes not simple types, the values are (mostly) automatically boxed/unboxed
    arrayList.set(i, listAtI);

arrayList.get(5); //returns the list at index 5
arrayList.get(5).get(5) // returns values from column 5 in row 5 

If you’re unfamiliar with lists in general, reading the answer here should provide valuable information on when to use which type of list

Leave a Comment