Monday, November 10, 2014

Selenium : 2D listin Java

2D list in Java

 

// Create an ArrayList of ArrayLists of Integers
ArrayList<ArrayList<Integer>> my2DArrayList = new ArrayList<ArrayList<Integer>>();
// add in a few ArrayLists. These contain the "rows" of the 2D ArrayList
my2DArrayList.add(new ArrayList<Integer>());
my2DArrayList.add(new ArrayList<Integer>());
my2DArrayList.add(new ArrayList<Integer>());
// you can retrieve rows using get(), then treat that 1D arrayList as the column.
my2DArrayList.get(0).add(1);
my2DArrayList.get(0).add(2);
my2DArrayList.get(1).add(3);
my2DArrayList.get(1).add(4);
my2DArrayList.get(1).add(0);
my2DArrayList.get(2).add(5);
// my2DArrayList now contains this:
// row 0: 1, 2
// row 1: 3, 4, 0
// row 2: 5
// to retrieve a specific element, you need to first get the ArrayList of the row you want, then retrieve the column from that arraylist you want
// get element at row 1 and column 2
int number = my2DArrayList.get(1).get(2);


No comments:

Post a Comment