What I’m looking for is a two dimensional array of Strings. Where Strings in the same row should be unique, but with allowing row duplicates.
I’m using a list where each row is a set:
List<Set<String>> bridges = new ArrayList<Set<String>>();
I have a method that returns a set of strings:
Set<String> getBridges(){
Set<String> temp = new HashSet<String>();
// Add some data to temp
temp.add("test1");
temp.add("test2");
temp.add("test3");
return temp;
}
Now in the main method, I’ll call getBridges() to fill the list that I have:
List<Set<String>> bridges = new ArrayList<Set<String>>();
Set<String> tempBridge = new HashSet<String>();
for(int j=0;j<5;j++){
for(int k=0;k<8;k++){
// I call the method and store the set in a temporary storage
tempBridge = getBridges();
// I add the the set to the list of sets
bridges.add(tempBridge);
// I expect to have the list contains only 5 rows, each row with the size of the set returned from the method
System.out.println(bridges.size());
}
}
Why I’m getting the list as a one dimensional array of the size 5*8? how to fix this?
You need to fix your loop: