Java - Write code to Trim a string or word by removing both first and last blank character

Requirements

Write code to Trim a string or word by removing both first and last blank character.

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(trim(str));
    }/*from  w  w  w  .  j a va  2  s.c  om*/

    /**
     * <p>Trim a string or word by removing both first and last blank character.</p>
     * @param str original string
     * @return trimmed string.
     */
    public static String trim(String str) {
        str = str.trim();
        if (str.charAt(0) == ' ') {
            str = str.substring(1, str.length());
        }
        return str;
    }
}