Skip to content

Commit

Permalink
Add correct formating
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarasmarkov committed Nov 12, 2024
1 parent 0d512e4 commit 45af92c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/main/java/core/basesyntax/FileWork.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

public class FileWork {
public String[] readFromFile(String fileName) {
//write your code here
try (BufferedReader reader = new BufferedReader(new FileReader(new File(fileName)))) {
try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
String line;
List<String> allSortedWords = new LinkedList<>();
while ((line = reader.readLine()) != null) {
Arrays.stream(line.split(" "))
.map(String::toLowerCase)
.filter(s -> s.charAt(0) == 'w').map(s -> {
char last = s.charAt(s.length()-1);
if (!(last >= 'a' && last <= 'z')) {
s = s.substring(0, s.length()-1);
}
return s;
char last = s.charAt(s.length() - 1);
if (!(last >= 'a' && last <= 'z')) {
s = s.substring(0, s.length() - 1);
}
return s;
}).forEach(allSortedWords::add);
}
return allSortedWords.stream().sorted().toArray(String[]::new);
Expand Down

0 comments on commit 45af92c

Please sign in to comment.