Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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

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

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...