Core API
How do I remove leading and trailing white space from string?
package org.kodejava.lang; public class TrimStringExample { public static void main(String[] args) { String text = " tattarrattat "; System.out.println("Original = " + text); System.out.println("text.length() = " + text.length()); // The trim() method will result a new string object with a leading and // trailing while space removed. text = text.trim(); System.out.println("Result = " + text); […]
Artikel oleh Wayan · Sumber: Kode Java ↗
Terjemahan artikel ini belum tersedia. Isi asli ditampilkan.
package org.kodejava.lang;
public class TrimStringExample {
public static void main(String[] args) {
String text = " tattarrattat ";
System.out.println("Original = " + text);
System.out.println("text.length() = " + text.length());
// The trim() method will result a new string object with a leading and
// trailing while space removed.
text = text.trim();
System.out.println("Result = " + text);
System.out.println("text.length() = " + text.length());
}
}
The result of the code snippet above:
Original = tattarrattat
text.length() = 22
Result = tattarrattat
text.length() = 12
