Java - Write code to filter Break Line with regex

Requirements

Write code to filter Break Line with regex

Demo

import java.util.Collection;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{
    public static void main(String[] argv){
        String lines = "boo\nk2s.com";
        System.out.println(filterBreakLine(lines));
    }/*from  www  .  j a  v a  2  s  .c om*/
    
    public static String filterBreakLine(String lines) {
        Pattern p = Pattern.compile("\\r\\n|\\r");
        Matcher m = p.matcher(lines);
        return (m.replaceAll("")).replaceAll("\\s+", " ");
    }
}

Related Exercise