Reputation: 139
`I wonder if anyone can help me with this problem or advise of a different way to go about it. I am using selenium webdriver, coding with java using testNG framework.
Basically, I have a method that extracts data from excel and stores them as arraylists. So for example, i have
this sort of data:
Region Text1 Text2 Text3
UK uk_t1 uk_t2 uk_t3
usa usa_t1 usa_t2 usa_t3
russ rus_t1 rus_t2 rus_t3
My method extracts all the information from excel and stores it into arraylist based on the column name
Example-
Arraylist<String>region = new ArrayList<String> ();
Arraylist<String>text1 = new ArrayList<String> ();
Arraylist<String>text2 = new ArrayList<String> ();
Arraylist<String>text3 = new ArrayList<String> ();
ArrayList<String> mydatacells = dataFromExcel(xlspath) // the method on the right is the one with the excel function
String xlspath = "example/mylocation";
int uk = 4; //location of the cell that contains the string uk
int usa = 8; //location of the cell that contains the string usa
int russ = 12; //location of the cell that contains the string russ
I then write the following to extract data specifically for a region
for(uk=4; uk<usa; uk++){
region.add(mydatacells.get(uk));
text1.add(mydatacells.get(uk));
text2.add(mydatacells.get(uk));
text3.add(mydatacells.get(uk));
} //the code assigns the value for uk
My problem now is that i need to use those values in another method and i need to get all the data.
Does anyone have an idea how this can be done or a more efficient way to do this?
Thanks
Upvotes: 0
Views: 248
Reputation: 114817
It's easier to have the data in a map - I assume, the values of the first column are unique and can be used as a key (index). Then I'd write a class to hold the values from a single row:
public class Location {
public String region;
public String text1;
public String text2;
public String text3;
}
Now, I'd
Upvotes: 1