Answer by user7294900 for How can I alternate between method calls?
You can use AtomicBoolean for thread safety Round Robin:AtomicBoolean roundRobin = new AtomicBoolean(false);void mainMethod() { Object val; if (roundRobin.compareAndSet(false, true)) { val =...
View ArticleAnswer by Corentin for How can I alternate between method calls?
Just declare a boolean variable in your class:public class MainClass { private boolean useMethod1 = true; public void mainMethod() { if (useMethod1) { method1(); } else { method2(); } useMethod1 =...
View ArticleAnswer by LorNap for How can I alternate between method calls?
You can use a queue: Inizialize queue: import java.util.LinkedList;import java.util.Queue;....Queue<String> methodQueue = new LinkedList<>();methodQueue.add("implMethod1");Use queue in your...
View ArticleAnswer by Sudip Bolakhe for How can I alternate between method calls?
private static boolean check = true;void mainMethod() { Obj val; if (check) { val = implMethod1(); check = !check; } else { val = implMethod2(); check = !check; }}This may help you.
View ArticleAnswer by Onkar Musale for How can I alternate between method calls?
static int count = 0;void mainMethod() { Obj val; if (somthing && count % 2 == 0) val = implMethod1(); else { val = implMethod2(); } count++;}You can try above code.
View ArticleAnswer by Mustahsan for How can I alternate between method calls?
Assuming somthing is a boolean variable, you can achieve it by using this strategy:void mainMethod() { Obj val; if (somthing) { val = implMethod1(); somthing = false; } else { val = implMethod2();...
View ArticleAnswer by Andronicus for How can I alternate between method calls?
I don't know if I understood the question correctly:boolean first = true;if (somthing && first) { val = implMethod1(); first = false;} else { val = implMethod2(); first = true;}
View ArticleHow can I alternate between method calls?
I want to call two methods, but I want to call only one of them at a time.The next time I want to call the one that was'nt called before, kind of a Round Robin techniqueExample:void mainMethod() { Obj...
View Article
More Pages to Explore .....