Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Returns null if the given string is not null and contains no characters,
     * the string itself otherwise.
     *
     * @param string the string.
     * @return null if the given string is not null and contains no characters,
     * the string itself otherwise.
     */
    public static String nullIfEmpty(String string) {
        return string != null && string.trim().length() == 0 ? null : string;
    }
}