java - Performance Improvement in the code -
problem statement is-
in case inclusion null, , exclusion has values, need check whether temp there in exclusion, if temp there in exclusion don't or can out of loop, suppose temp not there in exclusion call method. implemented same feature below not sure whether can improve more or not. looks me can improve more without using boolean stuff guess. stuff in main needs in method , going called lot of times
public static void main(string[] args) { string temp = "77"; // can 0 string inclusion = null; string exclusion = "100;77;71"; boolean bb = false; if(inclusion !=null) { system.out.println("site inclusion not null"); } else { (string exc: exclusion.split(";")) { if(exc.equals(temp)) { bb =true; break; } } if(!bb) { // call method } } }
i'd suggest using stringtokenizer instead of string.split(). discussed in this thread, quite bit faster.
public static void main(string[] args) { string temp = "77"; // can 0 string inclusion = null; string exclusion = "100;77;71"; boolean bb = false; if(inclusion !=null) { system.out.println("site inclusion not null"); } else { stringtokenizer st = new stringtokenizer(exclusion, ";"); while (st.hasmoretokens()) { if (temp.equals(st.nexttoken())) { bb = true; break; } } if(!bb) { // call method } } }
Comments
Post a Comment