private static String removeLastNewline(String str){
  int strlen=str.length();
  if (strlen == 0) {
    return str;
  }
  int lastNewline=str.lastIndexOf("\n");
  if (strlen == lastNewline + 1) {
    return str.substring(0,strlen - 1);
  }
 else {
    return str;
  }
}

private static String removeLastNewline ( String str ) { int strlen = str . length ( ) ; if ( strlen == 0 ) { return str ; } int lastNewline = str . lastIndexOf ( "\n" ) ; if ( strlen == lastNewline + 1 ) { return str . substring ( 0 , strlen - 1 ) ; } else { return str ; } }
if the last char in a given string is newline , return a string without the newline as last char
