-1

In python if you have a tuple or list of the form, myTuple = (a,b,c), you can assign equality to different variables by saying var1, var2, var3 = myTuple. I was wondering if there was any way to do an analogous thing in Java.

Eli Yablon
  • 103
  • 3
  • 2
    No, you need to do it explicitly. E.g. a=array[0], b=array[1], c=array[2] etc. – pveentjer Jan 23 '22 at 02:55
  • Alright, makes sense. Thanks. – Eli Yablon Jan 23 '22 at 02:56
  • Currently not possible I guess, I have seen this features only in dynamic programming languages like `Python` and `JavaScipt`. In `JS` you can do this `const [a, b, c] = [1, 2, 3]` – 27px Jan 23 '22 at 03:37
  • By the way, "assign equality" makes no sense. What you are talking about is simply assigning or assignment. The python feature is called "tuple assignment" ... and there is no equivalent language feature in Java – Stephen C Jan 23 '22 at 03:50

1 Answers1

0

In java , you cannot assign different variables values simultaneaously like this

var1, var2, var3 = myTuple.

You will have to do somthing like this :

int val[] = {1,2,3,4};
            int a,b,c,d=0;
        
                a = val[0];
                b = val[1];
                c = val[2];
                d = val[3];
Gurkirat Singh Guliani
  • 1,009
  • 1
  • 4
  • 19