任何方式来声明在线阵列? [英] Any way to declare an array in-line?

查看:64
本文介绍了任何方式来声明在线阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有一个方法M(),它字符串数组作为参数。有没有一种方法,当我拨打电话我就可以宣布这个数组在线?即相反的:

 的String [] =可疑交易报告{嗒嗒,哎,哟};
M(可疑交易报告);

我可以只是一条线替换此,避免声明名为变量,我永远不会使用?


解决方案

 米(新的String [] {嗒嗒,哎,哟});

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆