Replace the brackets and commas with empty space.

String formattedString = myArrayList.toString()
    .replace(",", "")  //remove the commas
    .replace("[", "")  //remove the right bracket
    .replace("]", "")  //remove the left bracket
    .trim();           //remove trailing spaces from partially initialized arrays
Answer from user489041 on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java array › print an array without brackets and commas
Print an Array Without Brackets and Commas | Baeldung
April 7, 2025 - We created a stream of our content array with Stream.of() and then joined all elements with an empty string to generate a final string without commas and brackets.
🌐
Know Program
knowprogram.com › home › java print array without brackets
Java Print Array Without Brackets - Know Program
April 25, 2022 - Java Print Array Without Brackets | In this section, we print the array without brackets and commas to do this we use replace() method and the Arrays.toString() method available in Java.
🌐
Coderanch
coderanch.com › t › 440397 › java › Removing-brackets-arraylist-printout
Removing brackets from arraylist printout. (Beginning Java forum at Coderanch)
Suppose your ArrayList is declared as new ArrayList<String>(); then you can do this: If you are not familiar with generics or what the <String> means, it's really the type of objects in the array list. ArrayList<String> means a array list containing strings. ArrayList<ABC> means a array list containing ABC object. K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP ... Not really. Your code will print all the values vertically.
🌐
Tutorials7
forum.tutorials7.com › 1546 › how-print-arraylist-without-the-square-brackets-and-in-java
How to print an ArrayList without the square brackets [ and ] in Java?
Java · How to print an ArrayList without the square brackets [ and ] in Java? All categories · C# (84) PHP (18) Java (46) JavaScript (195) Web Development (42) SEO (0) Other (13) How to create a Map in Java? How to create a List in Java? How to make two dimensional array in Java?
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-print-list-items-without-brackets-in-java
How to Print List Items Without Brackets in Java? - GeeksforGeeks
October 24, 2023 - // Java Program to demonstrate // print list items without brackets import java.io.*; import java.util.Arrays; import java.util.List; // Driver Class public class GFG { // main function public static void main(String[] args) { List<String> myList = Arrays.asList( "Item-01", "Item-02", "Item-03"); // Result Printed for (String item : myList) { System.out.print(item + " "); } } } Output ·
🌐
Instanceofjava
instanceofjava.com › 2018 › 02 › java-convert-array-to-string-without-brackets.html
How to convert array to string without brackets in java - InstanceOfJava
We can convert array to string by iterating array and capturing each element from an array and append to StringBuilder/StringBuffer so that final output will be string without brackets.
Find elsewhere
🌐
Javatpoint
javatpoint.com › how-to-print-arraylist-without-brackets-java
How to Print Arraylist Without Brackets Java - Javatpoint
How to Print Arraylist Without Brackets Java with java tutorial, features, history, variables, programs, operators, oops concept, array, string, map, math, methods, examples etc.
🌐
Know Program
knowprogram.com › home › how to print arraylist without brackets java
How to Print Arraylist Without Brackets Java - Know Program
April 17, 2022 - How to Print Arraylist Without ... the elements are printed within the brackets. To do this we can use replace method which replaces the brackets by space....
🌐
Reddit
reddit.com › r/javahelp › reformatting arraylist output: returning an arraylist's contents without the brackets/commas
r/javahelp on Reddit: Reformatting ArrayList output: Returning an ArrayList's contents without the brackets/commas
October 17, 2012 -

Edit: Solved! Thank you dartalley!

Made a post earlier about a program checking the validity of passwords written in textfields or read from files and this is the continuation, sorta. (Thanks a ton to those who helped, btw!) I have to return the ArrayList of passwords that did not meet the requirements, but I can't remove the brackets/commas:

[334455 The password must contain at least one alphabetic character.
, george The password must contain at least one digit.
, 4sale The password must be at least 6 characters long.
, abcdef The password must contain at least one digit.
, apples The password must contain at least one digit.
, aa11b The password must be at least 6 characters long.
, pilotproject The password must contain at least one digit.
, mypassword The password must contain at least one digit.
]

I can't manipulate it and return it as an ArrayList. If I do, it'll call the toString method of the ArrayList class and return them all anyways! I tried StringBuilder and StringTokenizer as well as setting delimiters to filter out the things I don't need, but those work for Strings, not an ArrayList of them.

I'm thinking I need to re-define the definition of the toString method within the ArrayList class, but that seems too complicated. I have to be missing something. Any help is appreciated. Thanks!

🌐
EDUCBA
educba.com › home › software development › software development tutorials › java tutorial › print array in java
Print Array in Java | 8 Useful Techniques to Print Array in Java
July 4, 2023 - Guide to Print Array in Java. Here we have discussed Techniques to Print Array in Java in 8 Different Methods with codes and outputs.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Stack Overflow
stackoverflow.com › questions › 28402860 › print-arraylist-without-brackets
java - print arraylist without brackets - Stack Overflow
... A simple hack would be to replace all [ and ] characters with "" using replaceAll. getDivisors(drome).toString().replaceAll("[\\[\\]]",""); But this works only because your data structure doesn't include any Strings that might contain real ...
🌐
Tutorials7
tutorials7.com › qa › java › how-to-print-an-arraylist-without-the-square-brackets-and-in-java
How to print an ArrayList without the square brackets [ and ...
The output MUST be without the square brackets [ ]; ... ArrayList<Integer> n = new ArrayList<>(); n.add(4); n.add(5); n.add(434); n.add((int) 9.5); System.out.println(n); ... When printing the result - you can make it String and then use it's .replace function - and replace the brackets with nothing "";
🌐
Sololearn
sololearn.com › en › Discuss › 777890 › how-do-i-print-the-characters-inside-an-arraylist-without-brackets-showing
How do i print the Characters inside an Arraylist without brackets [] showing? | Sololearn: Learn to code for FREE!
i thought .size might do it but its only showing the size of the array i tried y but this just shows the array list inside brackets maby i need .get()? but i dont know how to integrate it. ArrayList<Character> y = new ArrayList<Character>(); y.add((char)37); y.add((char)38); System.out.print(y.size()); javaarraylistchar ·
Top answer
1 of 14
12

You are probably calling System.out.println to print the list. The JavaDoc says:

This method calls at first String.valueOf(x) to get the printed object's string value

The brackets are added by the toString implementation of ArrayList. To remove them, you have to first get the String:

String errorDisplay = errors.toString();

and then strip the brackets, something like this:

errorDisplay = errorDisplay.substring(1, errorDisplay.length() - 1);

It is not good practice to depend on a toString() implementation. toString() is intended only to generate a human readable representation for logging or debugging purposes. So it is better to build the String yourself whilst iterating:

List<Integer> errors = new ArrayList<>();
StringBuilder sb = new StringBuilder();
for (int x = 1; x<10; x++) { 
    errors.add(x);
    sb.append(x).append(",");
}
sb.setLength(sb.length() - 1);
String errorDisplay = sb.toString();

Note that this is not an array, just a String displaying the contents of the list. To create an array from a list you can use list.toArray():

// create a new array with the same size as the list
Integer[] errorsArray = new Integer[errors.size()];
// fill the array
errors.toArray(errorsArray );

EDIT: From an object-oriented perspective one could argue that errors and errorsDisplay conceptually belong together in a class, e.g:

public class Errors {

    private final List<Integer> codes = new ArrayList<>();

    public void add(int error) {
        codes.add(error);
    }

    public Stream<Integer> get() {
        return codes.stream();
    }

    @Override
    public String toString() {
        return codes.stream()
            .map(Object::toString)
            .collect(Collectors.joining(", "));
    }
}
2 of 14
4

Short answer: System.out.println(errors.toString().substring(1, errors.toString().length() - 1))

Explanation: when you call System.out.println(obj) with an Object as a parameter, the printed text will be the result of obj.toString(). ArrayList.toString() is implemented in a way that makes it represent its content between brackets [] in a comma separated concatenation of each of the contained items (their .toString() representation as well).

It is not a good practice to rely on another class's toString() implementation. You should use your own way to format your result.