Write code to check if a string is not empty.
Use && (logical and) operator
check for null value then check for the length of the string after trim.
//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; } }