How do I remove leading and trailing white space from string?

package org.kodejava.example.lang;

public class TrimStringExample {
    public static void main(String[] args) {
	String text = "     tattarrattat     ";
	
	//
	// The trim() method will result a new string object with a leading and
	// trailing while space removed.
	//
	System.out.println("Result: " + text.trim());
    }
}

Wayan Saryada

Programmer, runner, recreational diver, live in the island of Bali, Indonesia 🇮🇩. Mostly programming in Java, creating web based application with Spring Framework, Hibernate / JPA.

Leave a Reply