I don't understand why my variable "len" doesn't take on the shortest string? I don't believe I'm using the length() method incorrectly. Please help.
package com.codegym.task.task07.task0709;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Expressing ourselves more concisely
*/
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<>();
String len = null;
for (int i = 0; i < 5; i++){
list.add(reader.readLine());
}
for (int i = 0; i < list.size(); i++){
len = list.get(0);
if (list.get(i).length() < len.length()){
len = list.get(i);
System.out.println(len);
}
}
for (int i = 0; i < list.size(); i++){
if (list.get(i).length() == len.length()){
System.out.println(len);
}
}
}
}
Thanks in advance!