replace a string with another string using java 8.

Here we will replace all the old character or string with new character or string using java 8.

  • Stream.of() used to create a sequential Stream from a number of arguments.
  • Inside map() function r.replace(“is”, “was”) all “is” string is replaced with “was” string.
  • Print the new string though forEach() method.
import java.util.stream.Stream;

public class ReplaceTest {
	public static void main(String[] args) {
		String s1 = "Your technology is Java";
		Stream.of(s1).map(r -> r.replace("is", "was")).forEach(System.out::println);
	}
}

Output :-
Your technology was Java

replace a string with another string using java 8. Read More »