Here you can find the source of trim(String s)
private static String trim(String s)
//package com.java2s; //License from project: Open Source License import java.util.Scanner; public class Main { /**//from ww w . j ava 2 s . c o m * Removes all ending \r and/or \n */ private static String trim(String s) { if (s == null) return null; Scanner scanner = new Scanner(s); String res = ""; while (scanner.hasNextLine()) { if (!res.equals("")) { res = res + "\n"; } res = res + scanner.nextLine(); } return res; } }