---------------------- android培训、java培训、期待与您交流! -------------------------
静态导入:
import static 导入一个类中的静态方法而不必导入整个类
import
System.out.println(Math.abs(3-7));//可以省略类名
System.out.println(Math.max(3,7));;//这个则不行
或者把所需要的这个类的静态方法全部引入,则可以省略类名
import static java.lang.Math.*;
System.out.println(Math.abs(3-7));
System.out.println(Math.max(3,7));
可变参数:
1)只能出现在参数列表的最后,用三个点表示
2)调用可变参数的方法时,编译器可为该可变量参数隐含创建一个数组,在方法体中以数组的形式访问可变参数
class VariableParameter
public static void main(String[] args){
for each 循环:
在JDK5.0中新增强For循环。
for ( type 变量名:集合变量名 ) { … }
集合变量可以是数组或实现了Iterable接口的集合类,()中定义了迭代的变量。
public class GenericList
{
public static void main(String[] args)
{
List<String> strs = new ArrayList<String>();
strs.add("关于加强型for循环");
strs.add("这是个小练习");
strs.add("miximixi");
for (String str:strs){
System.out.println(str)
}
}
}
自动装箱与自动拆箱:
class
{
Integer box=3;//3自动装箱为Integer类型
}
}
因为数字小,多次使用的频率高,没必要每一个数字对应一个对象,这是一种设计模式,称为享元模式(flyweight)
即使用方法Integer.valueOf()转化也相同
Integer a=Integer.ValueOf(100);
Integer b=Integer.ValueOf(100);
System.out.println(a==b); //true
Integer x=Integer.ValueOf(128);
Integer y=Integer.ValueOf(128);
System.out.println(x==y); //false
---------------------- android培训、java培训、期待与您交流! -------------------------
详情查询:黑马训练营