tags:

views:

142

answers:

1

Hi Have a List of array, like

[[{x509Cert=x509cert.pem, accountNumber=652827, serviceProviderName=Sun, privateKey=pk, userName=0BS0Y72NBN, passWord=VuXYG4hZPS}], [{x509Cert=x509cert.pem, accountNumber=698000, serviceProviderName=Sun, privateKey=my.key, userName=0BS0Y72NAWWSS, passWord= VuXYG4hZPS}]]

This was stored in an object, i got it converted to List and have 2 object, now I need the key-pair to be stored and should be able to access whenever I access [0].accountNumber should give be 652827 and if I say Object[1].accountNumber should give me 698000

This is the way I'm doing it right now

List<Object> wordList = java.util.Arrays.asList((Object[]) o2);  
for (Object o : wordList)
 System.out.println(java.util.Arrays.deepToString((Object[]) o));

Any help!!

+1  A: 

You can only do the foo[1].accountNumber if you create foo as an array of a type which has the accountNumber field (otherwise the compiler doesn't have a clue).

I would suggest printing out the classname of the objects in the list, so you can see what you are actually dealing with and which interfaces it implements. You can then create foo as an array of that type and do something like:

  Foo[] foo = new Foo[o2.length);
  .... loop over o2 copying each element o2[i] into foo[i] like "foo[i] = (Foo) o2[i]"
 System.out.println(foo[0].accountNumber);
 System.out.println(foo[1].accountNumber);
Thorbjørn Ravn Andersen
Well thanks for the comment, I figured out the solution myself :). It was not that easy as u have mentioned.
Panther24
Then either your description is not complete, or your solution overly complex.
Thorbjørn Ravn Andersen