Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

double array to String

 
zoyu mi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to use the toString() method but I dont how to chance an array of double primitive type into a string of only the values of the array.
Help please. Very confused
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrays don't override the toString() method. So if you want to print the contents of an array, you have to iterate over the array and add each element to a StringBuilder (or just print them as you go). Or you can use java.util.Arrays.toString() for 1D arrays and Arrays.deepToString() for multi-dimensional arrays (which are really just arrays of arrays in Java).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic