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!!
-
Once you have the object, cast it to a HashMap and then access the keys accordingly.Susheel Javadi– Susheel Javadi2009年11月16日 08:23:44 +00:00Commented Nov 16, 2009 at 8:23
-
Unfortunately is a String that is returned :(Vivek– Vivek2009年11月16日 10:33:41 +00:00Commented Nov 16, 2009 at 10:33
1 Answer 1
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);
-
Well thanks for the comment, I figured out the solution myself :). It was not that easy as u have mentioned.Vivek– Vivek2009年11月20日 14:57:24 +00:00Commented Nov 20, 2009 at 14:57
-
Then either your description is not complete, or your solution overly complex.Thorbjørn Ravn Andersen– Thorbjørn Ravn Andersen2009年11月20日 15:54:21 +00:00Commented Nov 20, 2009 at 15:54