本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7590835
建立时间:2006年5月29日




[J2SE]Java1.5语言新特性简单总结
软件技术

lhwork 发表于 2006/7/14 16:45:59

1. 自动装箱与拆箱 对应C# 例1.1  Integer i = 10;  int j = i;  2. 更优化的for循环 对应就C#---foreach循环 例2.1  String[] names = { "BadBoy","GoodBoy","HappyGirl","sadGirl" };  for(String option: names) {    System.out.println(option);   } 例2.2 加泛型 对应C++模板  import java.util.*;    ArrayList<String> animals = new ArrayList<String>();  animals.add("Dog");  animals.add("Cat");  animals.add("Chick");  animals.add("Cow");  for(String option : animals) {    System.out.println(option);   }  3.参数可变的方法和printf 例3.1  定义:  public int sum(int... n) {   //传过来n为一个int型数组   int tempSum;   for(int option : n) {     tempSum+=option;    }   /*   for(int i = 0; i < n.length; i++) {     tempSum+=n[i];    }   */   return tempSum;   }  调用1: sum(1);  调用2: sum(1,2);  调用3: sum(1,2,3,4); 例3.2 printf方法,  对应c语言的printf  int x = 10;  int y = 20;  int sum = x + y;  System.out.printf("%d + %d = %d",x,y,sum);4. 枚举 例4.1  public enum MyColors {    red,   black,   blue,   green,   yellow   }    MyColors color = MyColors.red;  for(MyColors option : color.values()) {    System.out.println(option);   }/**不能在switch语句里这样写case MyColors.red: *这样编译器不会让你通过*/switch(color) {  case red:  System.out.println("best color is "+red);  break; case black:  System.out.println("NO " + black);  break; default:  System.out.println("What");  break; }5.静态引用 例5.1  1.5版本以前的写法是:     import java.lang.Math; //程序开头处      ...      double x = Math.random();   1.5版本中可以这样写   import static java.lang.Math.random; //程序开头处      ...       double x = random(); 


阅读全文(1638) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.047 second(s), page refreshed 144756620 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号