public static void sort_names(String[] names) {

        Map<String, List<String>> map = new TreeMap<>();
        for (String name : names) {
            String lastName = name.split("\\s")[1];
            if(!map.containsKey(lastName)) {
                map.put(lastName, new ArrayList<String>());
            }
            map.get(lastName).add(name);
        }

        for (String lastName : map.keySet()) {
            for (String name : map.get(lastName)) {
                System.out.println(name);
            }
        }
    }