zoukankan      html  css  js  c++  java
  • 集合

    Collection----Java中对一些数据结构和算法进行了封装即是集合。集合也是一种对象,用于存储、检索和传输对象。
    1、长度可变2、类型可不同3、内存空间可不固定
    ----常用函数add();clear();contains();iterator()迭代,遍历元素;remove();size();toArray();
    ----迭代函数iterator----常用函数hasNext();next();remove(),当迭代遍历元素时如果想删除,必须用迭代里面的remove函数。
    一、List
    1、ArrayList
    ----常用函数contains(Object o);get(int index);set(int index, E element)
    2、LinkedList
    ----常用函数addFirst(E e) ;addLast(E e) ;getFirst();getLast();pop();push(E e);removeFirst();removeLast()
    二、Set
    1、HashSet
    2、TreeSet
    Map---一组“键对象Key+值对象Value”,Key不可以重复,Value可以重复
    ----常用函数put(K key, V value);keySet();values();
    一、HashMap
    二、TreeMap
    各类的区别
    一、List与Set。
    1、List是有序的,Set是无序的,这里的顺序是指放入与拿出的索引顺序
    2、List里面的元素是可以重复的,Set里面的元素是不可以重复的
    二、ArrayList与LinkedList
    1、ArrayList适合查询和修改,LinkedList适合增加和删除
    三、HashSet与TreeSet
    1、HashSet是按哈希码来存放元素,TreeSet是按字典顺序来存放元素
    2、HashSet速度快,TreeSet速度慢

  • 相关阅读:
    NYOJ 625 笨蛋的难题(二)
    NYOJ 102 次方求模
    ZJU Least Common Multiple
    ZJUOJ 1073 Round and Round We Go
    NYOJ 709 异形卵
    HDU 1279 验证角谷猜想
    BNUOJ 1015 信息战(一)——加密程序
    HDU 1202 The calculation of GPA
    "蓝桥杯“基础练习:字母图形
    "蓝桥杯“基础练习:数列特征
  • 原文地址:https://www.cnblogs.com/quanby/p/5411062.html
Copyright © 2011-2022 走看看