Home > Java > javaTutorial > body text

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

Susan Sarandon
Release: 2024-10-26 21:49:03
Original
533 people have browsed it

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>
Copy after login

You can simply declare the array in-line when calling the m() method:

<code class="java">m(new String[]{"blah", "hey", "yo"});</code>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!