Home >Java >javaTutorial >How to Pass Arrays as Arguments in-line Without Using Named Variables?
Declaring Arrays In-Line Without Named Variables
In your scenario, you want to avoid declaring intermediate variables when passing arrays as arguments. Here's how you can declare an array in-line:
Instead of using a named variable like:
<code class="java">String[] strs = {"blah", "hey", "yo"}; m(strs);</code>
You can simply declare the array in-line when calling the m() method:
<code class="java">m(new String[]{"blah", "hey", "yo"});</code>
This approach eliminates the need for an intermediate variable, such as strs, which you would have otherwise declared solely to hold the array values for the method call.
The above is the detailed content of How to Pass Arrays as Arguments in-line Without Using Named Variables?. For more information, please follow other related articles on the PHP Chinese website!