Hello guys,
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..

Recommended Answers

All 3 Replies

I don't think hashtable is the correct structure for the data you are trying to store if you are just using a string for the key and a string for the value. In a hashtable, the keys are supposed to be unique for each unique record, but in your post you keep re-using the same keys over and over again. Think of it this way. If I give the hashtable a key, it is supposed to find that key and return to me the associated value. In your example, if I give the key "userNo", what value is the hashtable supposed to return?

Maybe if you describe what you are trying to accomplish, someone will be able to help you design a better structure for your data.

@ kramerd. Am just using the Dataprovider concept in the TestNg. so each record will be passed to the method randomly and i never faced any probs like u said.. is there any other way to add. it.

No, sorry, you can not do what you're asking with a hashtable. I tried to describe to you before the way hashtables work. Let's say you try to put the following key/value pairs into hashtable, something like this.

myHashTable.put("browser", "*iexplore");
myHashTable.put("browser", "*mozilla");

Line 2 will replace the value "*iexplore" with the value "*mozilla" because you are using the same key for 2 different values. Each key in the hashtable must be unique.

Again, as I said before, perhaps if you explain what it is you are trying to accomplish, someone can help you design a better structure for your data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.