4

Data present in LinkedHashMap:-

{
 contacts={
 id={
 version=6,
 lastUpdatedTimeStamp=1377,
 contactID=23,
 firstName=B,
 lastName=K
 }
 }
}

Here, "contacts" & "id" are objects.

I am able to get the values of "contacts" :

LinkedHashMap map = restClient.getLinkedHashMap();
Object contactObj = map.get("contacts");

But how to get the value of "firstName"?

Any help or guidance will be well appreciated.

meda
45.5k14 gold badges95 silver badges123 bronze badges
asked Aug 26, 2013 at 14:01
1
  • First share your contacts and id classes. Commented Aug 26, 2013 at 14:03

1 Answer 1

3

You should cast the contactObj to the class whose primitive you want to access. Ex, if your class for contactObj is Contact, then you should do:

Contact contactObj = (Contact) map.get("contacts");

and then you can access the methods/primitives in the class that are accessible from this point. Ex, say your class is like

Class Contact{
String firstname;
public String getFirstName(){
 return this.firstname;
 }
} 

So, you can access the first name like as shown below:

contactObj.getFirstName();
answered Aug 26, 2013 at 14:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.