This should work, yet it is failing the requirement "The program should read 5 strings from the keyboard and write them to the list of strings". I even printed the strings ArrayList after adding all 5 strings and they were all added. :///
package com.codegym.task.task07.task0708;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Longest string
*/
public class Solution {
private static List<String> strings;
public static void main(String[] args) throws Exception {
//write your code here
strings = new ArrayList<String>();
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> longestString = new ArrayList<String>();
String longest = "";
for (int i = 0; i < 5; i ++){
strings.add(input.readLine());
}
System.out.println(strings);
for (int i = 0; i < strings.size(); i++){
if(strings.get(i).length() > longest.length()){
longest = strings.get(i);
}
}
longestString.add(longest);
strings.remove(longest);
for (String word : strings){
if(word.length() == longest.length()){
longestString.add(word);
}
}
for (String each : longestString){
System.out.println(each);
}
}
}