A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

  1. package com.wxy;

  2. import java.util.*;

  3. import javax.swing.text.html.HTMLDocument.Iterator;

  4. public class ColletionTest8
  5. {
  6.         public static void main(String[] args)
  7.         {
  8.                 ArrayList<Object> al = new ArrayList<Object>();
  9.                 al.add(new Person3("Steve", 23));
  10.                 al.add(new Person3("Steve", 23));
  11.                 al.add(new Person3("Larry", 21));
  12.                 al.add(new Person3("Gates", 26));
  13.                 al = singleElement(al);
  14.                 for(Object obj : al)
  15.                 {
  16.                         Person3 p =(Person3)obj;
  17.                         System.out.println("name:"+"="+p.getName() +"----"+"age:"+"="+p.getAge());
  18.                 }
  19.                
  20.         }

  21.         private static ArrayList<Object> singleElement(ArrayList<Object> al)
  22.         {
  23.                 ArrayList<Object> list  = new ArrayList<Object>();
  24.                 java.util.Iterator<Object> it = al.iterator();
  25.                 while(it.hasNext())
  26.                 {
  27.                         Object obj = it.next();
  28.                         if(!(list.contains(obj)))
  29.                         {
  30.                                 list.add(obj);
  31.                         }
  32.                 }
  33.          
  34.        
  35.                 return list;
  36.         }

  37. }

  38. class Person3
  39. {
  40.         private String name;
  41.         private int age;
  42.         public Person3(String name, int age) {
  43.                 this.name = name;
  44.                 this.age = age;
  45.         }

  46.         public String getName() {
  47.                 return name;
  48.         }

  49.         public int getAge() {
  50.                 return age;
  51.         }
  52.         @Override
  53.         public boolean equals(Object obj)
  54.         {
  55.                 if(!(obj instanceof Person3))
  56.                         return false;
  57.                 Person3 p = (Person3)obj;
  58.                 return (this.name.equals(p.name)) &&( this.age == p.age);
  59.         }


  60. }
复制代码

3 个回复

倒序浏览
我只想说为什么代码中没有一个注释,没有思路就算了
回复 使用道具 举报
叶顺达 发表于 2015-8-5 19:29
我只想说为什么代码中没有一个注释,没有思路就算了

这代码是我自己写的,纯粹是想拿些黑马币满足入学要求,没注释没有思路,不好意思,时间有限,刚辞职一边复习一边刷积分还望见谅
回复 使用道具 举报
我也想转技术分,但这种发这样小白的程序能赚么??请指教
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马