0

How can I print an array, array1, in one command like array.toString or something similar that actually prints array1 as an array like 1 3 4 or something similar and not as a string like [I@1242719c. Maybe we can turn it to a ArrayList and then we can print it easily?

3
  • @lngo:Is this a math ex? I tried 'array.toString' and prints it with a loop. It's whether you recall the static method of Arrays or not, no? Commented Sep 1, 2011 at 8:14
  • no it's not a math ex. It's a question of politeness if one expects help to give as detailed information as possible. Please remember that people answering here do that voluntary, it's not that they are paid by stackoverflow and it's there duty. Commented Sep 1, 2011 at 8:18
  • Sure, but i did explain what I think or suggested the ArrayList. I don't know what you more expected. Writing in the question: "How can I print an array in one command?" would be rude indeed. Commented Sep 1, 2011 at 8:29

3 Answers 3

12
Arrays.toString(array1)

and if it is multidimensional array

Arrays.deepToString(array1)
Sign up to request clarification or add additional context in comments.

Comments

6
Arrays.toString(array1)

should do the trick

Comments

3
 Arrays.toString(myArray);

According to the javadoc, it calls the toString() method of the objects in your array.

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.