Is there a good class that can count occurrences of specific lines in java? I would like to keep a list of names and then create unique email addresses for each name. For each occurrence of the last name, I would like to increase the number by one.
Ex: If I have 3 people with the last name Smith, I would like their address to be smith1 @ (Address), smith2 @ (Address) and smith3 @ (Address). I saw the Map class, but I cannot initialize it correctly. Is there a class that I can use to store a list of strings and their occurrences?
Map , , (), ( ).
:
Map<String, Integer> nameOccurrences = new HashMap<String, Integer>();
nameOccurrences.put("Smith", 1);
, :
if (nameOccurrences.containsKey("Smith")) { ... }
Integer occurrences = nameOccurrences.get("Smith");
, . , - , , .
- , . Multiset - google-guava .
Source: https://habr.com/ru/post/1787345/More articles:Augmented reality with large and complex markers - opencvReleasing loaded texture on webgl - webglHashMap как статический член в java - javaDoes the iPhone display sliding photos / images (e.g. photo library and Facebook app)? - iphoneWriting a function using recursion functions or a higher order - haskellHow can I draw a panel so that it does not blink? - c #SPAN tag ignored with JAWS read screen - htmlIntelligent access to a specific element of the second array of dimensions - phpЛенивый поиск значения словаря с использованием сеанса без состояния - c#Если проверка формы jquery в порядке, то я хочу запустить функцию перед отправкой формы - jqueryAll Articles