20180915

今天主要学习了:

1.类的定义格式:

创建java文件,与类名相同

public class 类名{

数据类型  属性名称1;

数据类型  属性名称2;

…

}
例如:

public class Phone {

 
 

/*

 
 

 * 属性

 
 

 */

 
 

String brand;// 品牌型号

 
 

String color;// 颜色

 
 

double size; // 尺寸大小

 
 

}

 

2.集合的创建

扫描二维码关注公众号,回复: 3209095 查看本文章

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);

  }

 

猜你喜欢

转载自www.cnblogs.com/zhanglu123/p/9652021.html