几种数据结构初学

List链表

List接口实现了Collection接口,将Collection接口中的方法在List中也都有体现。

常用的方法如:

int size()
boolean isEmpty()
boolean contains(Object o)
Iterator< E > iterator()
boolean add(E e)
boolean remove(Object o)
void clear()

常用已实现List

ArrayList
LinkedList 双向链表

Set集合

Set接口也是实现了Collection接口,区别于List无法存储重复的元素,且存入与取出的顺序不尽相同

常用已实现Set

HashSet

Map集合

Map中的数据是成对存在的(K, V )对,K值不能重复,V值可以重复

常用方法

int size()
boolean isEmpty()
boolean containsKey()
boolean containsValue()
V get(Object key)
V put(K key, V value)
V remove(Object key)
Set< K > keySet()

常用已实现Map

HashMap

Map遍历方法

遍历Key

Map<Integer,Character> map = new HashMap<>();

Set<Integer> keySet = map.KeySet();

Iterator<Integer> it = keySet.iterator();
while(it.hasNext()){
    int code = it.next();
    char ch = map.get(code); 
}

遍历键值对

Map<Integer,Character> map = new HashMap<>();

Set<Map<Integer,Character>> entrySet = map.EntrySet();

Iterator<Map.Entry<Integer,Character>> it = entrySet.iterator();
while(it.hasNext()){
    Map.Entry<Integer,Character> entry = it.next();
    int code = entry.getKey();
    char ch = entry.getValue();
}

forEach方法

for (Entry<String, String> entry: map.entrySet()) {
    int key = entry.getKey();
    String value = entry.getValue();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值