Collection Array List Array ListUser listsnew Array ListUser

  • Slides: 16
Download presentation

集合(Collection)

集合(Collection)

范型化 • 约束Array. List中所要放元素的类别 • Array. List<User> lists=new Array. List<User>();

范型化 • 约束Array. List中所要放元素的类别 • Array. List<User> lists=new Array. List<User>();

排序 • Collections: 具类 • 取最大和最小的元素:Collections. max()、Collections. min()。 • Collections类主要是对列表进行操作 • sort(); • sort()只接受Comparable对象的list

排序 • Collections: 具类 • 取最大和最小的元素:Collections. max()、Collections. min()。 • Collections类主要是对列表进行操作 • sort(); • sort()只接受Comparable对象的list

Iterator接口用法举例 import java. util. *; public class Test { public static void main(String[] args)

Iterator接口用法举例 import java. util. *; public class Test { public static void main(String[] args) { Array. List h = new Array. List(); h. add("1 st"); h. add("2 nd"); h. add(new Integer(3)); h. add(new Double(4. 0)); Iterator it = h. iterator(); while ( it. has. Next() ) { System. out. println(it. next()); } }

Properties类 类似Hash. Map • Key, value

Properties类 类似Hash. Map • Key, value

Properties类 import java. util. *; class Prop. Test{ public static void main(String[] args) {

Properties类 import java. util. *; class Prop. Test{ public static void main(String[] args) { Properties pps=new Properties(); try { pps. load(new File. Input. Stream("d: \test. properties")); Enumeration em=pps. property. Names(); //枚举类 while(em. has. More. Elements()) { String str. Key=(String)em. next. Element(); //em. . next. Element()返回Object类 String str. Value=pps. get. Property(str. Key); System. out. println(str. Key+"="+str. Value); } }catch(Exception e){ e. pri nt. Stack. Trace(); } } }

Thank you!

Thank you!