package javalike;public class Test12 { public static void main(String[] args) { String str = " Learning the Java Language in javalike channel "; System.out .println("Before removing the empty space at the beginning and end of the string"); System.out.println(str); System.out .println("\nAfter removing the empty space at the beginning and end of the string"); System.out.println(str.trim()); } }
Before removing the empty space at the beginning and end of the string Learning the Java Language in javalike channel After removing the empty space at the beginning and end of the string Learning the Java Language in javalike channel
package javalike;public class Test12 { public static void main(String[] args) { String str = " java like "; System.out.println("String before trim:" + str); System.out.println("String after trim:" + str.trim()); } }
String before trim: java like String after trim:java like
package javalike;public class TrimExample { public static void main(String args[]) { String str = new String(" How are you?? "); System.out.println("String before trim: " + str); System.out.println("String after trim: " + str.trim()); } }
String before trim: How are you?? String after trim: How are you??
package javalike;public class TrimExample { public static void main(String args[]) { String str = new String(" 11 22 33 14 15 5 1365 1478 98 7 "); String array[] = str.split(" "); int array2[] = new int[array.length]; for (inti = 0; i < array.length; i++) array2[i] = Integer.parseInt(array[i]); for (int i = 0; i < array2.length; i++) System.out.print(array2[i] + " "); } }
java.lang.NumberFormatException
package javalike;public class TrimExample { public static void main(String args[]) { String str = new String(" 11 22 33 14 15 5 1365 1478 98 7 "); str = str.trim(); String array[] = str.split(" "); int array2[] = newint[array.length]; for (int i = 0; i < array.length; i++) array2[i] = Integer.parseInt(array[i]); for (int i = 0; i < array2.length; i++) System.out.print(array2[i] + " "); } }