I have below multiple variables.
JSONObject one = new JSONObject();
JSONObject two = new JSONObject();
JSONObject three = new JSONObject();
I tried below way
JSONObject one, two, three;
one = two = three = new JSONObject();
It is giving error when I am trying to write on those objects.
[UPDATE]
JSONObject one = null, two = null , three = null ;
one = two = three = new JSONObject();
one.put("test", 1);
JSONObject one = null, two = null , three = null ;Note that the java compiler will initialize the variables to null. Explicitly initializing them to null actually adds more operations because you are initializing each variable twice. What is the motivation behind your question? Are you trying to save two lines of source code?