Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public class App
  2. {
  3. public static void main( String[] words ) {
  4. HashMap<String, Integer> map = new HashMap<>();
  5. String firstWord = null;
  6.  
  7. for (String word : words) {
  8. if (!map.containsKey(word)) {
  9. map.put(word, 1);
  10. } else {
  11. map.put(word, map.get(word) + 1);
  12.  
  13. }
  14. }
  15. System.out.println(Arrays.toString(words));
  16.  
  17. for (Map.Entry<String, Integer> entry : map.entrySet()) {
  18. System.out.println(entry.getKey() + " : " + entry.getValue());
  19. if (entry.getValue() == 1) {
  20. firstWord = entry.getKey();
  21. }
  22. }
  23. System.out.println(firstWord);
  24.  
  25. }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement