java 传参数时 类型后跟 3个点 "..." 的意义
2018-02-05 12:40
441 查看
1、直接看代码就知道什么含义了!
public class StringDemo{
public static void main(String[] args){
testPoints("I love my job.");//一个参数传入
testPoints("you","and","me");//3个String参数传入
testPoints(new String[]{"you","and","me"});//可以看到传入三个String参数和传入一个长度为3的数组结果一样,再看例子
System.out.println("---------------------------------------------------------");
testPoints(7);
testPoints(7,9,11);
testPoints(new Integer[]{7,9,11});
}
public static void testPoints(String... s){
if(s.length==0){
System.out.println("没有参数传入!");
}else if(s.length==1){
System.out.println("1个参数传入!");
}else{
System.out.println("the input string is-->");
for(int i=0;i<s.length;i++){
System.out.println("第"+(i+1)+"个参数是"+s[i]+";");
}
System.out.println();
}
}
public static void testPoints(Integer... itgr){
if(itgr.length==0){
System.out.println("没有Integer参数传入!");
}else if(itgr.length==1){
System.out.println("1个Integer参数传入!");
}else{
System.out.println("the input string is-->");
for(int i=0;i<itgr.length;i++){
System.out.println("第"+(i+1)+"个Integer参数是"+itgr[i]+";");
}
System.out.println();
}
}
}
--------------------------------------------------------
输出:
1个参数传入!
the input string is-->
第1个参数是you;
第2个参数是and;
第3个参数是me;
the input string is-->
第1个参数是you;
第2个参数是and;
第3个参数是me;
---------------------------------------------------------
1个Integer参数传入!
the input string is-->
第1个Integer参数是7;
第2个Integer参数是9;
第3个Integer参数是11;
the input string is-->
第1个Integer参数是7;
第2个Integer参数是9;
第3个Integer参数是11;
public class StringDemo{
public static void main(String[] args){
testPoints("I love my job.");//一个参数传入
testPoints("you","and","me");//3个String参数传入
testPoints(new String[]{"you","and","me"});//可以看到传入三个String参数和传入一个长度为3的数组结果一样,再看例子
System.out.println("---------------------------------------------------------");
testPoints(7);
testPoints(7,9,11);
testPoints(new Integer[]{7,9,11});
}
public static void testPoints(String... s){
if(s.length==0){
System.out.println("没有参数传入!");
}else if(s.length==1){
System.out.println("1个参数传入!");
}else{
System.out.println("the input string is-->");
for(int i=0;i<s.length;i++){
System.out.println("第"+(i+1)+"个参数是"+s[i]+";");
}
System.out.println();
}
}
public static void testPoints(Integer... itgr){
if(itgr.length==0){
System.out.println("没有Integer参数传入!");
}else if(itgr.length==1){
System.out.println("1个Integer参数传入!");
}else{
System.out.println("the input string is-->");
for(int i=0;i<itgr.length;i++){
System.out.println("第"+(i+1)+"个Integer参数是"+itgr[i]+";");
}
System.out.println();
}
}
}
--------------------------------------------------------
输出:
1个参数传入!
the input string is-->
第1个参数是you;
第2个参数是and;
第3个参数是me;
the input string is-->
第1个参数是you;
第2个参数是and;
第3个参数是me;
---------------------------------------------------------
1个Integer参数传入!
the input string is-->
第1个Integer参数是7;
第2个Integer参数是9;
第3个Integer参数是11;
the input string is-->
第1个Integer参数是7;
第2个Integer参数是9;
第3个Integer参数是11;
相关文章推荐
- java 传参数时 类型后跟 3个点 "..." 的意义
- java 传参数时 类型后跟 3个点 “...” 的意义
- java 传参数时 类型后跟 3个点 “...” 的意义
- java中传参数时,在类型后面跟"..."的使用
- java 执行sql错误 传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确。参数 1 (""): 数据类型 0x38 未知
- JAVA类型后面跟3个点(可变长度参数列表)
- java 参数类型后跟三个点详解:test(String... s)
- JAVA类型后面跟3个点(可变长度参数列表)
- java泛型之带有两个类型参数的泛型示例
- 验证参数传递引发的Java编译错误“No enclosing instance of type XXX is accessible" 及匿名内部类
- Java类型后面的3个点的含义
- 使用百度API报102错误{"status":102,"message":"MCODE参数不存在,mobile类型mcode参数必需"}
- java 方法的传入参数 参数类型后面的三个点的作用。
- java方法参数基本类型和方法参数是引用类型的区别
- iOS微信支付获取支付参数解析 iOS解析java json数据 例如:\"age\":\"28\"
- Java-String类型的参数传递问题 推荐
- Java基础加强:静态导入及可变参数和增强for循环 ,基本数据类型的自动拆箱和装箱
- java 线程池 两个定时方法的参数意义
- 02.java语言基础-参数的值传递机制-基本数据类型
- Hadoop中mapred.child.java.opds参数意义