java语言中的面向对象特性.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
java语言中的面向对象特性

List list=new ArrayList(); list.add(new Integer(3)); list.add(new Integer(4)); list.add(new Integer(3)); list.add(new Integer(2)); List的get(int index)方法返回集合中由参数index指定的索引位置的对象,第一个加入到集合中的对象的索引位置为0, for( int i=0,ilist.size;i++) {System.out.println(list.get(i));} 输出结果为:3 4 3 2. List按索引排列: Map(映射) 集合中的每一个元素包含一对键对象和一对值对象,集合中没有重复的键对象,值对象可以重复,它的有写实现类能对集合中的键对象进行排序. Map map=new HashMap(); map.put(1,Mon); map.put(1,Monday); map.put(2,monday); 由于第一次和第二次加入到Map中的键对象都是1,所以第一次加入的值对象将被覆盖,而第二个和第三个的值对象虽然相同,但是键对象不一样,所以分配了不同的地址空间,所以不会覆盖,也就是说一共有两个元素在Map集合中. Map有两种比较常用的实现: HashMap和TreeMap. Hashmap按照哈希算法来存取键对象,有很好的存取能力,为了保证HashMap能正常工作,和HashSet一样,要求当两个键对象通过equals()方法比较为true时,这两个键对象的hashCode()方法返回的哈希码也一样。 TreeMap实现了SortedMap接口,能对键对象进行排序,和TreeSet一样,TreeMap也支持自然排序和客户化排序两种方式,以下程序中的TreeMap会对四个字符串类型的键对象“1”,“3”,“4”,“2”进行自然排序: Map map=new TreeMap(); map.put(1,Monday); map.put(3,Wendsday); map.put(4,Thursday); map.put(2,Tuesday); //返回集合中所有键对象的集合 Set keys=map.keySet(); Iterator it=keys.iterator(); while(it.hasNext) { String key=(String)it.next(); //根据键对象得到值对象 String value=(String)map.get(key); System.out.println(key+ +value); } 以上输出结果为:1 Monday 2 Wendsday 3 Thursday 4 Tuesday Properties类(一) Property list is another common key/element pair, consisting of string names and associated string elements The Properties class extends Hashtable , implements the Enumeration interface If a property list has been properly populated with only String keys and elements, you can save and restore it from files or other I/Ostreams 构造方法 public Properties() Properties类(二) 常用方法 public String getProperty(String key) public String getProperty(String key,String default) private void save(OutputStream out,String header) public synchronized void load(InputStream in) throws IOException public

文档评论(0)

little28 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档