Confusion in convertin Object[][] to hashtable[mod-20] | Selenium Forum
M
Posted on 22/02/2016
Sir,

mod-20, part-5..
I have a Object[][] with data in it..This array has about 5 columns.I need to convert this Object[][] to hashtable <String,String>.
But sir, this should have been Hashtable inside hashtable right...as there are multiple columns in Object[][].

Am not clear with the concept of Hashtable conversion used here...Could you explain in more detail sir..

Please refer attachments:

M
Replied on 22/02/2016

Pls find SuiteA as attachment


M
Replied on 23/02/2016

We create a single column in Object array
Multiple rows can be there
Each row on object array can hold one thing only as there is single column

That one thing we keep as a hastable. hashtable is like a bag
It can hold multiple values


M
Replied on 23/02/2016

sir... pls refer attachment...

is the logic right ???[refer attachment]

in 1 Dimensional array i put keys in column..is that fine ?

Responsive image

M
Replied on 23/02/2016

seems ok.


M
Replied on 23/02/2016

If i code as per the logic above[partial coding]..am getting ArrayoutOfBounds exception sir.. Responsive image

Please find attachments:


M
Replied on 23/02/2016

suiteA,suite.xls respectively attached


M
Replied on 23/02/2016

Got it sir...

Could you please explain : X[rowNumArray][0]=H; statement please....
Code:
----------
Hashtable<String,String>H=new Hashtable<String,String>();
Object[][]X =new Object[NumRows][1];
X[rowNumArray][0]=H;// <------Please explain in detail....

Issue:
Since H is name of hashtable & has key n value [2 entities].... We are assigning it to a 2D array.
How is that possible since we have not used H.get("<some key">)????????


M
Replied on 23/02/2016

http://stackoverflow.com/questions/5554734/what-causes-a-java-lang-arrayindexoutofboundsexception-and-how-do-i-prevent-it


M
Replied on 23/02/2016

Got it sir...

Could you please explain : X[rowNumArray][0]=H; statement please....
Code:
----------
Hashtable<String,String>H=new Hashtable<String,String>();
Object[][]X =new Object[NumRows][1];
X[rowNumArray][0]=H;// <------Please explain in detail....

Issue:
Since H is name of hashtable & has key n value [2 entities].... We are assigning it to a 2D array.
How is that possible since we have not used H.get("<some key">)????????


M
Replied on 24/02/2016

Hashtable<String,String>H=new Hashtable<String,String>(); //hash tables is created
Object[][]X =new Object[NumRows][1];//object created
X[rowNumArray][0]=H;// <------Please explain in detail....//in object X[row num][0] value of H will be loaded. so you can save many different hash tables in object.