• Post Reply Bookmark Topic Watch Topic
  • New Topic

Easy way to remove brackets from arraylist output?  RSS feed

 
Michael Huynh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to get my output to be displayed without the brackets. I feel like it's a simple thing but just can't figure it out.

The output looks like this

22 ([1, 2, 11])
33 ([1, 3, 11])
44 ([1, 2, 4, 11, 22])
55 ([1, 5, 11])
66 ([1, 2, 3, 6, 11, 22, 33])
77 ([1, 7, 11])

But I want it to have no brackets displayed so it looks like this
22 (1, 2, 11)
33 (1, 3, 11)
44 (1, 2, 4, 11, 22)
55 (1, 5, 11)
66 (1, 2, 3, 6, 11, 22, 33)
77 (1, 7, 11)

 
Mark King
Ranch Hand
Posts: 55
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can parse it using the replace method. Alternatively you can override the toString implementation of your ArrayList.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
Or you can loop through the List printing each element with your own print instruction. Note a useful little trick for removing the end of a String:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!