易截截图软件、单文件、免安装、纯绿色、仅160KB

Java变长参数

在Java5中提供了变长参数,也就是在方法定义中可以使用个数不确定的参数,对于同一方法可以使用不同个数的参数调用,例如:print("hello");print("hello","lisi");print("hello","张三");下面介绍如何定义可变长参数以及如何使用可变长参数。
1、可变长参数方法的定义
使用...表示可变长参数,例如
print(String... args){
   ...
}
在具有可变长参数的方法中可以把参数当成数组使用,例如可以循环输出所有的参数值。
print(String... args){
   for(String temp:args)
      System.out.println(temp);
}
2、可变长参数的方法的调用
调用的时候可以给出任意多个参数,例如:
print("hello");
print("hello","lisi");
print("hello","张三");
3、注意事项
3.1 在调用方法的时候,如果能够和固定参数的方法匹配,也能够与可变长参数的方法匹配,则选择固定参数的方法。看下面代码的输出:
package ch6;
import static java.lang.System.out;
public class VarArgsTest {
 public static void main(String[] args) {
  VarArgsTest test = new VarArgsTest();
  test.print("hello");
  test.print("hello","zhangsan");
 }
 
 public void print(String... args){
  for(int i=0;i<args.length;i++){
   out.println(args[i]);
  }
 }
 
 public void print(String test){
  out.println("----------");
 }
}
3.2 如果要调用的方法可以和两个可变参数匹配,则出现错误,例如下面的代码:
package ch6;
import static java.lang.System.out;
public class VarArgsTest {
 public static void main(String[] args) {
  VarArgsTest test = new VarArgsTest();
  test.print("hello");
  test.print("hello","zhangsan");
 }
 
 public void print(String... args){
  for(int i=0;i<args.length;i++){
   out.println(args[i]);
  }
 }
 
 public void print(String test,String...args ){
  out.println("----------");
 }
}
对于上面的代码,main方法中的两个调用都不能编译通过。
3.3 一


相关文档:

Java中集合容器类List和Set的用法

List的用法
List包括List接口以及List接口的所有实现类。因为List接口实现了Collection接口,所以List接口拥有Collection接口提供的所有常用方法,又因为List是列表类型,所以List接口还提供了一些适合于自身的常用方法,如表1所示。
表1  List接口定义的常用方法及功能
从表1可以看出,List接口提供的适合于自身的 ......

利用Java实现压缩与解压缩(zip、gzip)支持中文路径

关键字: zip gzip
zip扮演着归档和压缩两个角色;gzip并不将文件归档,仅只是对单个文件进行压缩,所以,在UNIX平台上,命令tar通常用来创建一个档案文件,然后命令gzip来将档案文件压缩。
Java
I/O类库还收录了一些能读写压缩格式流的类。要想提供压缩功能,只要把它们包在已有的I/O类的外面就行了。这些类不是Reader ......

郭克华老师java视频教程下载地址(J2ME 和J2EE)


1.j2ee
http://0444.xue8xue8.com/computer/program/java/j2eeshuren/00.wmv
http://0444.xue8xue8.com/computer/program/java/j2eeshuren/01.wmv
http://0444.xue8xue8.com/computer/program/java/j2eeshuren/02.wmv
http://0444.xue8xue8.com/computer/program/java/j2eeshuren/03.wmv
http://0444.xue8xue8.com/c ......

【转】Java中的位运算符

【转】Java中的位运算符
原作者:Rosen Jiang 出处:http://www.blogjava.net/rosen
移位运算符
    包括:
    “>> 右移”;“<< 左移”;“>>> 无符号右移”
例子:
-5>>3=-1
1111 1111 1111 1111 1111 1111 1111 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号