How to convert List to String without commas and brackets
arraylist, java, printing
Solution
You can do it easily using replaceAll method like
String result = myList.toString().replaceAll("[\\[\\]]", "").replaceAll(",", " ");
Try the below program. Hope it meets your needs.
List<String> myList = new ArrayList<String>();
myList.add("a");
myList.add("b");
myList.add("c");
String result = myList.toString().replaceAll("[\\[\\]]", "").replaceAll(",", " ");
System.out.println(result);
Problem
Suppose array list is already created with elements a, b and c in them. but i only want to print the elements without the brackets and commas. would this work? ``` for(int i=0;i<list.size();i++){ String word = list.get(i); String result = word + " "; } System.out.print(result); ```