I studying the stream, I encountered a question. I have a List I need to sort by the length of the string, all the strings where there is a match of uppercase characters, if there are no such, then sort by alphabet.
List<String> phones = new ArrayList<>();
Collections.addAll(phones, "iPhone X", "Nokia 9", "Huawei Nexus 6P",
"Samsung Galaxy S8", "LG G6", "Xiaomi MI6", "Sony Xperia Z5",
"Asus Zenfone 3", "Meizu Pro 6", "Heizu Pro 6",
"pixel 2");
phones.stream().filter(s -> s.matches("A-Z")).sorted(Comparator.comparingInt(String::length)).forEach(System.out::println);
I try to use matches, but I make a mistake somewhere, since nothing is output. How can I fix this?