0 votes
1 view
in Java by (3.5k 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"};


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 (41k points)

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

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !