Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (4k points)

Let's say I have a method m() that takes an array of Strings as an argument. Is there a way I can just declare this array in-line when I make the call? i.e. Instead of:

String[] strs = {"a", "b", "c"};

m(strs);

Can I just replace this with one line, and avoid declaring a named variable that I'm never going to use?

1 Answer

0 votes
by (46k points)

Yeah, you can do it in one line like this:

m(new String[]{"a", "b", "c"});

Related questions

Browse Categories

...