Need help with hashTable
I have coded something which would return the contents of a excel sheet as a hashTable. The code is
public Object[][] validDataProviderScenarioOne() {
excelWorker excel = new excelWorker();
String pathValue = excelWorker.LocatingXls("Data.xls");
Hashtable<String, String>[] hashDrv =(Hashtable<String, String>[]) excel.contentReading(pathValue, "xxxxx_Login");
Object[][] obj = new Object[hashDrv.length][1];
for(int i=0; i<hashDrv.length; i++) {
obj[i][0] = hashDrv[i];
}
return obj;
}
now, if there are 3 rows in excel sheet it will have 3 sets of data in it. now what i want is, i want to add some data in the hashtable for each entry in the hashtable array
For eg : the contents of the sheet
User No userName password
1 xxxxxx yyyyy
2 aaaaaa bbbbb
3 cccccc ddddd
now in the hashTable i would like to add key as browser and value as *iexplore,*mozilla,*safari, but i dont want to add this in the excel sheet.
so my hasHtable will look like
userNo=1,userName=xxxxx,password=yyyyy,browser=*iexplore
userNo=1,userName=xxxxx,password=yyyyy,browser=*mozilla
userNo=1,userName=xxxxx,password=yyyyy,browser=*safari
userNo=2,userName=aaaaaa,password=bbbbb,browser=*iexplore
userNo=2,userName=aaaaaa,password=bbbbb,browser=*mozilla
userNo=2,userName=aaaaaa,password=bbbbb,browser=*safari
userNo=3,userName=cccccc,password=ddddd,browser=*iexplore
userNo=3,userName=cccccc,password=ddddd,browser=*mozilla
userNo=3,userName=cccccc,password=ddddd开发者_如何学运维,browser=*safari
plz help, thanx in advance
The best thing you can do is create a class that contains the fields you want, e.g
class User {
private int id;
private String username;
...
}
and return an array (or a Collection) of those.
Incidentally, why are you allocating and returning a two-dimensional array when the second dimension is hard-coded to one element? Why not just return a one-dimensional array?
精彩评论