0

I'm getting a list of strings from python code and need to read it in Java. When trying to read it, i get the hashCode

[Ljava.lang.Object;@7cf1bb78

I want to read the values in a list. In python my return is something like

return SUCCESS(OK, params={'data':nameList()})

How would I read this in Java and print the contents not the hashCode. Currently I'm doing like

Object getNames = new Object();
getName = getNameList(); // This is thru Apache XML RPC Client
System.out.println(getName);

Any help or suggestions?

2
  • Uhm... your code is a bit confusing as you initialize the Object getNames, then "overwrite" it with an hashmap, then use another different object altogether, "getName" (without the "s"); if you want to print the list you have to iterate through it Commented Nov 12, 2009 at 8:43
  • getNames was a typo, I've corrected it. The reason for overwriting the Object with Hashmap was since I was trying to make it generic, anyway that doesn't make a difference. Commented Nov 12, 2009 at 9:17

2 Answers 2

1

You already have what you want. Try System.out.println(java.util.Arrays.toString(getName)); (the default toString() for an array in Java is not very useful).

Sign up to request clarification or add additional context in comments.

3 Comments

I tried System.out.println(java.util.Arrays.toString((Object[]) getAccount)); and the output was [] Any other was to try it?
This means you got an empty array back. Make sure that the server sends something useful.
There was some code issue in Python also, anyway thanks for the solution, it works fine now :)
0

The usual way to print out each item in a Java array would be something like:

for (Object name: (Object[]) getNameList()) {
  System.out.println(name);
}

But I suspect from your response to Aaron Digulla that (as he says) you're getting an empty array back. Try printing it out on the Python side and see if there's anything in it.

Comments

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.