Java tutorial
//package com.java2s; public class Main { public static String mergeLines(String linesText) { String ret_value = ""; String[] lines = linesText.split("\n"); if (lines != null) { for (String line : lines) { ret_value = ret_value + " " + line.trim(); } } else { ret_value = linesText.replaceAll("\t", "").replaceAll("\n", " "); } return ret_value.trim(); } }