Java Program to Replace All Line Breaks from Strings
Given a string, write a Java program to replace all line breaks from the given String.
Input - Geeks For Geeks Output - Geeks For Geeks
Line Break: A line break (“\n”) is a single character that defines the line change.
In order to replace all line breaks from strings replace() function can be used.
String replace(): This method returns a new String object that contains the same sequence of characters as the original string, but with a given character replaced by another given character.
public String replace(char old,char new)
- old: old character
- new: new character
Returns value: Returns a string by replacing an old character with the new character
Original String with line breaks - Replace all line breaks from strings String after replacing line breaks - Replace all line breaks from strings