I've read the correct solution and see that we are expected to display the data from the file our program reads in the form of characters, not strings. I just don't understand why it cannot be done in the string form, as the requirement is technically to "display everything except periods, commas, and spaces". So, why chars?
package en.codegym.task.pro.task15.task1506;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Scanner;
/*
Face control
*/
public class Solution {
public static void main(String[] args) {
/*
try (Scanner scanner = new Scanner(System.in)) {
List<String> lines = Files.readAllLines(Paths.get(scanner.nextLine()));
lines.forEach(str -> {
char[] chars = str.toCharArray();
for (char character : chars) {
if (character != ' ' && character != '.' && character != ',') {
System.out.print(character);
}
}
});
*/
try(
Scanner scanner = new Scanner(System.in);
){
List<String> contents = Files.readAllLines(Paths.get(scanner.nextLine()));
//fruits.forEach(fruit -> System.out.println(fruit));
contents.forEach(string -> {
string.replaceAll("\\s", "");
string.replaceAll(".", "");
string.replaceAll(",", "");
System.out.print(string);
});
} catch (Exception e) {
System.out.println("Something went wrong: " + e);
}
}
}