Hello.
There is an ArrayList<Character> , how can it be converted to a string and displayed on the screen without commas? In this version:
System.out.println(massStringList.toString()); Commas are inserted after each character. The string itself has its commas, so deleting everything is not an option.
Full view of the line to be displayed:
String s = "Текст, текст, текст, текст"; char[] massString = s.toCharArray(); int len = massString.length; Character[] array = new Character[len]; for (int i = 0; i < len ; i++) { array[i] = new Character(s.charAt(i)); } ArrayList<Character> massStringList = new ArrayList<>(asList(array)); The string is first converted to char[] , and then to Character[] , so that you can make an ArrayList from an array of characters. Crutches too, yes. And it needs exactly ArrayList , just the array does not fit.
I’m interested in how this can be done exactly by the Java API, I can do it through for , but these are some crutches, like for example:
for (Character chr : massString) { System.out.print(chr); } I met here a couple of discussions on a similar topic, but I didn’t see anything other than the said crutches.