void (String[] args) { List<String> l = new ArrayList<>(); for (String arg : args) { l.add(arg); } l.add("some str"); int bestLen = 100; String bestStr = null; for (String s : l) { if (bestStr == null || s.length() > bestLen) { bestStr = s; bestLen = s.length(); } } System.out.println(bestStr.length()); }