I have tried to delete keys and values of a map
but I have not yet achieved it, meanwhile I have created another map
.
Point 5 is the most important, then I show you what I have.
public class StringTest {
public static void main(String[] args) {
String stringTest = "En esta cadena tenemos mas cadenas que la cadena principal la primera vez que intente esta solucion no pude mas que intentar una y otra vez vez vez vez";
new StringTest(stringTest);
}
public StringTest(String string) {
String [] splitString = string.split(" ");
Map<String, Integer> mapString = new HashMap<String, Integer>();
mapString.put(splitString[0], 1);
for (int i=1; i <= splitString.length-1; i++){
if (mapString.containsKey(splitString[i])){
mapString.put(splitString[i], mapString.get(splitString[i])+1);
} else{
mapString.put(splitString[i], 1);
}
}
Map<String, Integer> newMap = new HashMap<String, Integer>();
for (Entry<String, Integer> entry : mapString.entrySet()){
if (entry.getValue()!=1){
newMap.put(entry.getKey(), entry.getValue());
}
}
System.out.println(newMap);
}
}