开发者

Java + List to HashMap

开发者 https://www.devze.com 2022-12-11 07:31 出处:网络
Hi Have a List of array, like [[{x509Cert=x509cert.pem, accountNumber=652827, serviceProviderName=Sun, privateKey=pk, userName=0BS0Y72NBN, passWord=VuXYG4hZPS}], [{x509Cert=x509cert.pem, accountNumbe

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 开发者_如何学Goshould 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!!


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消