字符串参数...在Java中 [英] String... parameter in Java

查看:142
本文介绍了字符串参数...在Java中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现对家庭作业的API,以及我的教练一直使用的符号,我不熟悉的API中的方法之一(根据的Javadoc)。

I have to implement an API for a homework assignment, and my instructor has used a notation I am unfamiliar with for one of the methods in the API (javadoc based).

public void method(String... strs);

什么的'...'是什么意思?后来看起来像我将需要调用使用一个字符串实际参数多个字符串实际参数同样的方法,以及...

What do the '...' mean? It later looks like I'll need to call this same method using a single string actual parameter, as well as multiple string actual parameters...

Java没有可选参数(据我所知),所以我有点困惑在这里...

Java doesn't have optional arguments (to my knowledge), so I am a little confused here...

推荐答案

这就是所谓的可变参数; <一href=\"http://docs.oracle.com/javase/6/docs/technotes/guides/language/varargs.html\">http://docs.oracle.com/javase/6/docs/technotes/guides/language/varargs.html

It's called varargs; http://docs.oracle.com/javase/6/docs/technotes/guides/language/varargs.html

这意味着你可以传递参数任意数量的方法(甚至为零)。

It means you can pass an arbitrary number of arguments to the method (even zero).

在方法,参数会自动放入指定类型的数组,您用来访问各个参数。

In the method, the arguments will automatically be put in an array of the specified type, that you use to access the individual arguments.

这篇关于字符串参数...在Java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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