有什么方法可以在线声明数组? [英] Any way to declare an array in-line?
本文介绍了有什么方法可以在线声明数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个方法 m() 将字符串数组作为参数.有没有一种方法可以在我打电话时直接声明这个数组?即而不是:
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 = {"blah", "hey", "yo"};
m(strs);
我可以只用一行替换它,并避免声明一个我永远不会使用的命名变量吗?
Can I just replace this with one line, and avoid declaring a named variable that I'm never going to use?
推荐答案
m(new String[]{"blah", "hey", "yo"});
这篇关于有什么方法可以在线声明数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文