Print array without brackets and commas

how to print array without brackets python
python print output without parentheses
remove brackets and commas from list python
python print list without brackets and commas
python printing a list without the brackets and single quotes
how to remove square brackets from list string in java
swift print array without brackets
javascript array to string without brackets

I'm porting a Hangman game to Android and have met a few problems. The original Java program used the console, so now I have to somehow beautify the output so that it fits my Android layout.

How do I print an array without the brackets and commas? The array contains slashes and gets replaced one-by-one when the correct letter is guessed.

I am using the usual .toString() function of the ArrayList class and my output is formatted like: [ a, n, d, r, o, i, d ]. I want it to simply print out the array as a single String.

I fill the array using this bit of code:

List<String> publicArray = new ArrayList<>();

for (int i = 0; i < secretWordLength; i++) {
    hiddenArray.add(secretWord.substring(i, i + 1));
    publicArray.add("-");
}

And I print it like this:

TextView currentWordView = (TextView) findViewById(R.id.CurrentWord);
currentWordView.setText(publicArray.toString());

Any help would be appreciated.

Basically, don't use ArrayList.toString() - build the string up for yourself. For example:

StringBuilder builder = new StringBuilder();
for (String value : publicArray) {
    builder.append(value);
}
String text = builder.toString();

(Personally I wouldn't call the variable publicArray when it's not actually an array, by the way.)

Output ArrayList to String without [,] (brackets) appearing, I need to store the ArrayList in a String without the brackets so I can work with it. EDIT: It should be noted that the one comma in the version I want  How do I print an array without the brackets and commas? The array contains slashes and gets replaced one-by-one when the correct letter is guessed. I am using the usual .toString() function of the ArrayList class and my output is formatted like: [ a, n, d, r, o, i, d ] .

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

How to print array/ list without brackets in python?, I want to print a list in python without the square brackets. It is always coming printing like [ to become an AI/ ML Engineer or Data Scientist! How do i print an array without the brackets and commas? The array contains slashes and gets replaced one by one when the correct letter is guessed. I am using the usual .toString() function of the ArrayList class and my output is formatted like: [ a, n, d, r, o, i, d ].

You can use join method from android.text.TextUtils class like:

TextUtils.join("",array);

How to convert array to string without brackets in java, how to remove square brackets from string in java java convert array to to StringBuilder/StringBuffer so that final output will be string without  If you want to print the elements of the list or array without using loops, then you can use the '*' symbol to print the list elements in a single line with space.

first

StringUtils.join(array, "");

second

Arrays.asList(arr).toString().substring(1).replaceFirst("]", "").replace(", ", "")

EDIT

probably the best one: Arrays.toString(arr)

How to print an ArrayList without the square brackets [ and ] in Java?, I need to print in Java an ArrayList - but without the square brackets [ ] - how can I do it? The output MUST be without the square brackets [ ];. For example I have  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more Convert array to string without brackets, commas, or spaces

With Java 8 or newer, you can use String.join, which provides the same functionality:

Returns a new String composed of copies of the CharSequence elements joined together with a copy of the specified delimiter

String[] array = new String[] { "a", "n", "d", "r", "o", "i", "d" };
String joined = String.join("", array); //returns "android"

With an array of a different type, one should convert it to a String array or to a char sequence Iterable:

int[] numbers = { 1, 2, 3, 4, 5, 6, 7 };

//both of the following return "1234567"
String joinedNumbers = String.join("",
        Arrays.stream(numbers).mapToObj(String::valueOf).toArray(n -> new String[n]));
String joinedNumbers2 = String.join("",
        Arrays.stream(numbers).mapToObj(String::valueOf).collect(Collectors.toList()));

The first argument to String.join is the delimiter, and can be changed accordingly.

How do i print the Characters inside an Arraylist without brackets , How do i print the Characters inside an Arraylist without brackets [] showing? i thought .size might do it but its only showing the size of the array i  If you have a numpy array to begin with rather than a list (since you mention a "real numpy array" in your post) you could use re.sub on the string representation of the array: print(re.sub('[\[\]]', '', np.array_str(a))) Again, this is assuming your array a was a numpy array at some point. This has the advantage of working on matrices as well.

How do I print a list without brackets?, Hey Henry, when you print out a list it is going to print out as a list, not I called .​join() on a string with a single empty space and a comma in it,  When printing the result - you can make it String and then use it's .replace function - and replace the brackets with nothing ""; . In your case the code will look like this:

How to print a list without brackets in Python, Printing only the list contents without brackets and markup can make the output To seperate each element with a comma followed by a space, set sep to ", " . Questions: This is my code that I used for my program. I’m having difficulties in displaying it the way I want which is without the brackets and commas. I want it to be like pyramids: X # XXX ### XXXXX ##### XXXXXXX ##### XXXXXXXXX ##### My code gives square brackets and commas that I don’t

Print list without brackets in a single row, Try the code given below, all the elements will be separated with a comma. name​= [“t”,”h”,”e”]. Print ( ',' .join(name)). Output:- t,h,e  When trying the below code, is there a more elegant way to output the numbers without the commas or brackets? Grid, as suggested in other threads, is not behaving as expected, nor did trying to force a blank space with Row[list," "] between each item work. The intent is to copy and paste the cleaned output for other uses.

Comments
  • The toString() method on the List interface is really just meant for debugging and logging. You shouldn't use it to present output to the user.
  • The replace method invocation for the right bracket mistakenly contains the left bracket. But otherwise it will work.
  • Just don't put elements containing brackets and commas in the list.
  • This shouldn't have been upvoted so highly due to above comment.
  • This is the best way for an Android context. Fast and easy.
  • TextUtils takes Iterable as well
  • For Android, this is the best answer and the method takes both arrays and lists.
  • The StringUtils is the cleaner option in my oppinion. +1
  • As a bonus StringUtils doesnt require a string array, it will work on Integers, Doubles, Objects, etc.
  • The question is about Java
  • this does work in java.. ["this","stuff"].join(","); = "this,stuff"