You can do like below:
Method:1
namesList1.forEach(name -> {
if (name.equalsIgnoreCase("Kumar")) {
namesList1.set(namesList1.indexOf(name), "Singh");
}
});
System.out.println(namesList1);
Method :2 (Suggested by @Holger)
namesList1.replaceAll(s -> s.equalsIgnoreCase("Kumar")? "Singh": s);
System.out.println(namesList1);
2
solved I am replacing value “Kumar” with “Singh” while Iterating ArrayList using Java 7, How it will convert using Java 8 Stream API?