Home  >  Article  >  Java  >  How to Pass Arrays as Arguments in-line Without Using Named Variables?

How to Pass Arrays as Arguments in-line Without Using Named Variables?

Susan Sarandon
Susan SarandonOriginal
2024-10-26 21:49:03527browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn