Search code examples
javab-tree

changing two values at a time in java


How can I change two values concurrently. I am writing a code for b-tree in java. But i am unable to modify two variables at a time. Like in C , we do so by using pointers. But how to do so in java? I hope my question is understandable.


Solution

  • I'm not sure I completely understand your question, but setting an object reference in Java is atomic. You can use that to change a set of multiple values at a time, e.g.:

    class BTreeState {
        int foo;
        long bar;
        String whatever;
    }
    
    //here you change foo, bar, whatever all at once
    state = new State(1, 2L, "something");