aspose file tools
The moose likes Java in General and the fly likes How do I remove the brackets from the ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How do I remove the brackets from the ArrayList" Watch "How do I remove the brackets from the ArrayList" New topic
Author

How do I remove the brackets from the ArrayList

Arun S. Nair
Greenhorn

Joined: Jul 22, 2012
Posts: 4
How do I remove the brackets from an ArrayList. This is my code. I need a loop that returns a string for my getBuiltInDevices. This code shown below is from one of my subclasses. I was supposed to add builtInDevices, which I did in my stockMain class. When I printed out the output I got [BulletScan M80 Sheetfed Scanner, Lenovo Wireless Mouse N3901A, Lenovo Headset P950]. How do I remove the brackets.



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32830
    
    4
What brackets in an ArrayList? Do you mean the square brackets which enclose the list of elements when you call toString()?
Override toString and return a different format. Create a utility class with a listToString(List<?>) method.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32830
    
    4
And welcome to the Ranch

I shall edit your post in line with this link and you can see how better it looks.
Arun S. Nair
Greenhorn

Joined: Jul 22, 2012
Posts: 4
Yes, I mean the brackets which enclose the list of the elements. I have tried to do a for loop but I am not able to solve it. What do i put in the parameter of add. I alreaady have a toString method.

String s="";
for(int i = 0;builtInDevices.get(i) !=null && i<builtInDevices.size();i++)
{
if(builtInDevices.get(i+1)==null)
{
s=s+builtInDevices.add();
}
else
{
s=s+builtInDevices.add() + ", ";
}
}
return builtInDevices;
}
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32830
    
    4
Yesterday, I wrote: . . . I shall edit your post in line with this link and you can see how better it looks.
Now it is your turn to use what it says in that link.

You need to tell us more details. How did you use the for loop? What do you mean about parameters to add()? I don’t think that will affect your output. We can’t help if we don’t know what you did.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How do I remove the brackets from the ArrayList
 
Similar Threads
Removing brackets from arraylist printout.
meaning of double angle brackets(<< >>) in Generics?
declaration
How do you remove a String [ ] from an ArrayList?
laptop for programming