kindly me if there other easy way optimise/implement code on below possibilities. variables home, bill, reg can either empty string("") or null depending on scenario.
my code
public void helloworld() { list items=new arraylist(); items.add("1"); // dummy list string home=""; // can null or empty string bill=null; // can null or empty string reg=""; // can null or empty if(!items.isempty()) { system.out.println("list not null"); if(home==null&&bill==null&®==null) { system.out.println("home null"); system.out.println("bill null"); system.out.println("reg null"); } if(home==null&&bill==null&®!=null) { system.out.println("home null"); system.out.println("bill null"); system.out.println("reg not null"); } if(home==null&&bill!=null&®==null) { system.out.println("home null"); system.out.println("bill not null"); system.out.println("reg null"); } if(home==null&&bill!=null&®!=null) { system.out.println("home null"); system.out.println("bill not null"); system.out.println("reg not null"); } if(home!=null&&bill==null&®==null) { system.out.println("home not null"); system.out.println("bill null"); system.out.println("reg null"); } if(home!=null&&bill==null&®!=null) { system.out.println("home not null"); system.out.println("bill null"); system.out.println("reg not null"); } if(home!=null&&bill!=null&®==null) { system.out.println("home not null"); system.out.println("bill not null"); system.out.println("reg null"); } if(home!=null&&bill!=null&®!=null) { system.out.println("home not null"); system.out.println("bill not null"); system.out.println("reg not null"); } } else { system.out.println("list null"); } } please advise. in advance.
just check home, bill, , reg individually, because have no dependency each other.
public void helloworld() { list items=new arraylist(); items.add("1"); // dummy list string home=""; // can null or empty string bill=null; // can null or empty string reg=""; // can null or empty if(!items.isempty()) { system.out.println("list not null"); system.out.println( home == null ? "home null" : "home not null" ); system.out.println( bill == null ? "bill null" : "bill not null" ); system.out.println( reg == null ? "reg null" : "reg not null" ); } else { system.out.println("list null"); } }
Comments
Post a Comment