daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top