• Post Reply Bookmark Topic Watch Topic
  • New Topic

beginner question about converting arrays to string  RSS feed

 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all
i have readily beginners question i guess .. just wanted to know if i can avoid looping
say i have
int arr[] = {0000,1111,2222,3333};

and i like to convert this array to string representation that will contain all the array element
except the first element so it will look like :

111122223333

of course there is no problem to make it with looping , but in this case i just want to know if i can avoid looping and get to
the result .

thanks all
 
Svend Rost
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

to my knowledge it's not possible to make such a string
without looping. Even if there were some arrayToString
method it would, internally, have to loop through the array.

/Svend Rost
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way is to call:

String s = Arrays.toString(arr);

and then use a regular expression to remove all of the non-numeric characters from s.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!