Last active
January 19, 2021 16:46
-
-
Save gledsoncruz/9b702dfb9b976fefc3f8966abf11874f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.Normalizer; | |
import java.util.stream.Collectors; | |
import java.util.*; | |
public class Pessoas { | |
public static String removeAcentos(String nome) { | |
if (nome != null){ | |
nome = Normalizer.normalize(nome, Normalizer.Form.NFD); | |
nome = nome.replaceAll("[^\\p{ASCII}]", ""); | |
} | |
return nome; | |
} | |
public static ArrayList<String> listNomes(ArrayList<String> nomes) { | |
ArrayList<String> tempList = new ArrayList<String>(); | |
for (String nome : nomes) { | |
tempList.add(removeAcentos(nome.toUpperCase())); | |
} | |
return tempList; | |
} | |
public static void main(String args[]) { | |
ArrayList<String> lista = new ArrayList<String>(); | |
lista.add("Pedro"); | |
lista.add("João"); | |
lista.add("Maria"); | |
lista.add("JOAO"); | |
lista.add("Alberto"); | |
lista.add("João"); | |
lista.add("MARiA"); | |
lista = listNomes(lista); | |
Map<String, Long> counterMap = lista.stream().collect(Collectors.groupingBy(e -> e.toString(), Collectors.counting())); | |
TreeMap<String, Long> sorted = new TreeMap<>(); | |
sorted.putAll(counterMap); | |
System.out.println(sorted); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment