Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class App
- {
- public static void main( String[] words ) {
- HashMap<String, Integer> map = new HashMap<>();
- String firstWord = null;
- for (String word : words) {
- if (!map.containsKey(word)) {
- map.put(word, 1);
- } else {
- map.put(word, map.get(word) + 1);
- }
- }
- System.out.println(Arrays.toString(words));
- for (Map.Entry<String, Integer> entry : map.entrySet()) {
- System.out.println(entry.getKey() + " : " + entry.getValue());
- if (entry.getValue() == 1) {
- firstWord = entry.getKey();
- }
- }
- System.out.println(firstWord);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement