Title Description: Given s = {"A", "B", "C", "D", "F", "E", "AB"}; S2 = {"A", "AB"}; Find out that the remaining elements in S2 are not included in S. Can be considered as the result of S-S2.
Idea: Using HashMap, the elements in s are stored in HashMap, and the value in <K,V> is assigned a value of 1, and then the elements in the S2 are traversed, if there is value+1 in S1, then the element of value 1 is found.
1 ImportJava.util.*;2 ImportJava.util.Map.Entry;3 Public classStringminute {4 Public Static voidMain (string[] args) {5String[] s = {"A", "B", "C", "D", "F", "E", "AB"};6string[] S2 = {"A", "AB"};7 8map<string, integer> map =NewHashmap<>();9 for(inti=0; i<s.length; i++){TenMap.put (S[i], 1); One } A for(inti=0; i<s2.length; i++){ - if(Map.containskey (S2[i])) { - intCount =Map.get (S2[i]); thecount++; - Map.put (S2[i], count); - } - } +Iterator iter =Map.entryset (). iterator (); - while(Iter.hasnext ()) { +map.entry<string, integer> Entry = (entry<string, integer>) Iter.next (); A if(Entry.getvalue () = = 1){ at System.out.println (Entry.getkey ()); - } - } - } -}
Given two array of strings, find out the different elements