0

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!!

2
  • Once you have the object, cast it to a HashMap and then access the keys accordingly. Commented Nov 16, 2009 at 8:23
  • Unfortunately is a String that is returned :( Commented Nov 16, 2009 at 10:33

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Well thanks for the comment, I figured out the solution myself :). It was not that easy as u have mentioned.
Then either your description is not complete, or your solution overly complex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.