使用Java实现面向对象编程(7)

集合:

Collection 不唯一 无序
List 不唯一 有序
Set 唯一 无序

 

Map    键值对存储的集合方式  

 

ArrayList : Object[]实现
LinkedList: 链表形式实现
HashMap: key:set value:collection

 

Vector ArrayList: 前者线程安全 后者重速度 线程不安全 前者增长幅度1倍 后者50%
HashTable HashMap: 前者线程安全 后者不安全 前者键值均不允许放null 后者 允许

 

Iterator:迭代器   (hasNext    next2个方法)

 

泛型:限制集合中存放的类型(引用数据类型)

 

回文:

public class Huiwen

{
  public static void main(String[] args)

  {
    String str = "123212";

    LinkedList list = new LinkedList();
    char[] chs =str.toCharArray();
    for(int i = 0;i < chs.length;i++)

    {
      list.addFirst(chs[i]);
    }
    String str1="";
    for(int i = 0;i < list.size();i++)

    {
      str1 += list.get(i);
    }

    if(str.equals(str1))

    {
      System.out.println("yes");
    }
  }
}

 

泛型:限制集合中存放数据的类型  (数据的类型只允许是引用数据类型)

 

由于list是有序的  所以可以采用访问下标

 

put 向集合中存放对象

 

map集合

key 是唯一的   value无所谓

 

get:根据key获取值

 

remove   根据键移除值

 

HashMap   允许有一个key为空 值无所谓 可空可不空
HashTable   key 不允许为空 值也不允许为空

posted on 2017-03-30 22:32  凌雨轩林  阅读(191)  评论(0编辑  收藏  举报

导航