Java - Write code to check if a string is Not Empty by using && (logical and)

Requirements

Write code to check if a string is not empty.

Use && (logical and) operator

Hint

check for null value then check for the length of the string after trim.

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String string = "book2s.com";
        System.out.println(isNotEmpty(string));
    }/*  ww  w  .j  av a  2 s. c o  m*/

    public static boolean isNotEmpty(String string) {
        return string != null && string.trim().length() > 0;
    }
}