20180915

今天主要学习了:

1.类的定义格式:

创建java文件,与类名相同

public class 类名{

数据类型  属性名称1;

数据类型  属性名称2;

…

}
例如:

public class Phone {


/*


 * 属性


 */


String brand;// 品牌型号


String color;// 颜色


double size; // 尺寸大小


}

 

2.集合的创建

ArrayList<要存储元素的数据类型变量名 = new ArrayList<要存储元素的数据类型>();

l 存储String类型的元素

ArrayList<String> list = new ArrayList<String>();

l 存储int类型的数据

ArrayList<Integer> list = new ArrayList<Integer>(); 

l 存储Phone类型的数据

ArrayList<Phone> list = new ArrayList<Phone>();

3.集合的遍历:

  for (int i = 0; i < list.size(); i++) {

  int n = list.get(i);

  System.out.println(n);

  }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2018-09-15 20:10  张禄  阅读(78)  评论(0编辑  收藏  举报