It is not looping through the if loop in the code. The desired o/p is:
This is real project with problems problems are tough to solve
My code:
public static void main(String[] args) {
String s = "This is real project with real problems real problems are tough to solve";
String key = "real";
int count = 0;
Map<Integer, String> map = new HashMap<Integer, String>();
StringTokenizer st = new StringTokenizer(s);
Integer v = null;
String next;
while (st.hasMoreElements()) {
next = st.nextToken();
// To assign unique key to the value in the string
if (v == null)
v = 1;
else
v++;
map.put(v, next);
}
System.out.println("before: " + map);
System.out.println(count);
//To delete the word "real" from the string
for (int i = 0; i <= map.size(); i++) {
//This is not working
if (map.containsValue("real") && count >= 1) {
//To delete value in the hashMap with ""
next = "";
}
count++;
}
System.out.println("After deleting: " + map );
}