class Test { void test(Object obj) { if (obj instanceof String && !((String) obj).isEmpty()) { System.out.println(((String) obj).trim()); } } }