package shuzu;

 public class Customer {
//从源码中 使用字段生成构造函数
public Customer(String good, int price) {
super();
this.good = good;
this.price = price;
}
private String good;
private int price;
//从源码中 使用 自动生成Get和Set方法
public String getGood() {
return good;
}
public void setGood(String good) {
this.good = good;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
//从源码中 自动生成tostring方法
@Override
public String toString() {
return "Customer [good=" + good + ", price=" + price + "]";
} }
 package shuzu;

 import java.util.ArrayList;

 public class Testlist {

     public static void main(String[] args) {
ArrayList<Customer> cus=new ArrayList<Customer>();
cus.add(new Customer("衬衫",100));//匿名对象
cus.add(new Customer("西裤",200));//匿名对象
cus.add(new Customer("鞋子",300));//匿名对象
Customer cc=new Customer("帽子",50);//明名对象
cus.add(cc);
for (int i=0;i<cus.size();i++){
Customer c=cus.get(i);
System.out.println(""+c.getGood()+""+c.getPrice()+"元");//没有自动生成 tostring方法时 输出方式
//System.out.println(""+c+"元");//自动生成toString方法时 输出方式
}
} }

最后两条输出语句  输出结果相同   效果不同

2016/1/21 练习 arraylist 1,添加 add() 2,遍历集合的更多相关文章

  1. FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM

    FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM T.. = Timeline support 支持时间轴 .S. = Slice t ...

  2. ”耐撕“团队 2016.3.21 站立会议3 2 1 GO!

    ”耐撕“团队 2016.3.21 站立会议 时间:2016.3.21  ① 17:20-17:45  ②17:55-18:10  总计40分钟 成员: Z 郑蕊 * 组长 (博客:http://www ...

  3. java中使用反射往一个泛型是Integer类型的ArrayList中添加字符串,反射的案例1.

    //------------------------- //废话不多说,直接上代码.代码里面添加了详细的解释. import java.lang.reflect.Constructor; import ...

  4. Technical Committee Weekly Meeting 2016.06.21

    Meeting time: 2016.June.21 1:00~2:00 Chairperson:  Thierry Carrez Meeting summary: 1.Add current hou ...

  5. Murano Weekly Meeting 2016.06.21

    Meeting time: 2016.June.21 1:00~2:00 Chairperson:  Kirill Zaitsev, from Mirantis Meeting summary: 1. ...

  6. 【转载】C#中ArrayList集合类使用Add方法添加元素

    ArrayList集合是C#中的一个非泛型的集合类,是弱数据类型的集合类,可以使用ArrayList集合变量来存储集合元素信息,任何数据类型的变量都可加入到同一个ArrayList集合中,因此使用Ar ...

  7. magento产品成功添加到购物车后跳转到不同页面 添加 add to cart 按钮

    1 添加产品到购物车成功后是跳转到购物车页面或不跳转.这个在后台可以设置 system -> configuration -> After Adding a Product Redirec ...

  8. 问题.NET--win7 IIS唯一密钥属性“VALUE”设置为“DEFAULT.ASPX”时,无法添加类型为“add”的重复集合

    问题现象:.NET--win7 IIS唯一密钥属性“VALUE”设置为“DEFAULT.ASPX”时,无法添加类型为“add”的重复集合 问题处理: 内容摘要:    HTTP 错误 500.19 - ...

  9. Arraylist JDk1.8扩容和遍历

    Arraylist作为最简单的集合,需要熟悉一点,记录一下---->这边主要是注意一下扩容和遍历的过程 请看以下代码 public static void main(String[] args) ...

随机推荐

  1. selenium webdriver 常用断言

    断言常用的有: assertLocation(判断当前是在正确的页面). assertTitle(检查当前页面的title是否正确). assertValue(检查input的值, checkbox或 ...

  2. oracle分析函数之ratio_to_report

    ratio_to_report主要完成对百分比的计算,语法为ratio_to_report(exp) over()也就是根据over窗口函数的作用区间,求出作用区间中的单个值在整个区间的总值的比重比如 ...

  3. win10 专业版 安装tornado 的步骤

    win10 专业版 安装tornado 的步骤: 1.下载tornado源码压缩包 下载网址:https://github.com/tornadoweb/tornado 若是没有github 账号可以 ...

  4. 在git提交时忽略已提交过或从线上拉取下来但本地已修改的文件

    一.忽略: git update-index --assume-unchanged [file-path] 命令中的file-path 就是需要忽略提价的文件的路径 例子: git update-in ...

  5. ubuntu14.04 Google Chrome can not be run as root

    问题如下图:

  6. 2014-4-5安装python以及基础知识

    1.下载安装 从python官网下载python2.7.6 https://www.python.org/download/releases/2.7.6 建议用迅雷下载 会比较快 2.交互式解释器 运 ...

  7. mysqldump快速导数据

    MySQL导出的SQL语句在导入时有可能会非常非常慢,经历过导入仅45万条记录,竟用了近3个小时.在导出时合理使用几个参数,可以大大加快导入的速度. -e 使用包括几个VALUES列表的多行INSER ...

  8. 2018/3/3 解析ThreadLocal源码

    今天听到一个老哥说道ThreadLocal在源码设计上面的一些好处,于是决定把ThreadLocal源码彻底分析一下. 首先,我们来看下set方法 可以看到,这个方法里,先获得了当前线程,之后将当前线 ...

  9. codevs4439 YJQ Requires Food

    题目描述 Description 神犇YJQ有n个不同的妹子和m种食物,每一天每一种食物只供应一个妹子吃的份量.在接下来的t天内,YJQ准备包养所有的妹子. 对于每个妹子,她在t天内都只会吃某些特定的 ...

  10. 【small项目】MySQL第二天早上第一次连接超时报错,解决方法com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:

    MySQL第二天早上第一次连接超时报错,解决方法com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link ...