1

I need a little help with converting an Obj-C code to Java code. Obj-C code :

NSArray * tmp = [_user.userDbAdapter executeQuery:query];
if ([[[tmp objectAtIndex:0] objectForKey:@"mediaType"] intValue] == M_COLLECTION_ANTHEM) 
{
    mtype = SECTYPE_AUDIO;
}

Java code :

ArrayList<Object> tmp = aUser.userDbAdapter.executeQuery(query);                
if(tmp.get(0)){
    //code                  
}

Is this the right way to do this...and how can I get objectForKey in Java ? Thanks in advance!

1 Answer 1

2

Your query will return an array of NSDictionary objects in the Obj-C code... in java my best guess would be it returns a array of objects that implement the Map interface (behaves the same way as the NSDictionary class: http://download.oracle.com/javase/1.4.2/docs/api/java/util/Map.html).

You can then use tmp.get(0).get("mediaType") (if the objects in the array implement the Map interface that is).

List<Map>* tmp = aUser.userDbAdapter.executeQuery(query);  
if (tmp.get(0).get("mediaType").intValue() == M_COLLECTION_ANTHEM) 
{
    mtype = SECTYPE_AUDIO;
}
Sign up to request clarification or add additional context in comments.

5 Comments

Damn, I didn't know that I can use get two times.Thanks really for the help!
There you go. Code edited and done for you. I think that should working (I am assuming the array returned contains objects implementing the Map interface though).
First get: List interface Second get: Map interface
Actually If I use List<Map>, and after I change the type of query to List<Map> I can't use the both get methods. If i stick to the ArrayList<Object> type I still can't use the second get method....
That's because the objects in the List are not Maps... do this to figure out what they are: tmp.get(0).class.toString() <- print that to something where you can see it!

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.