Array,Collection,Map的浅析

一、Array

1:Array是用来存储一组相同类型的集合,属于引用类型数据,集合中每一个元素都对应自己的下标。

2:优点:遍历非常快,查找某个元素效率最高。

      缺点:数组的长度改变只能在初始化时或使用System.arraycopy(src, srcPos, dest, destPos, length);

     Arrays.copyOf(original, newLength)去改变;增删减元素非常的繁琐。

package test;

import java.util.Arrays;

public class ArrayDemo {
	public static void main(String[] args) {
		int[] arr = new int[3];
		int[] arr1 = { 2, 5, 8 };
		int[] arr2;
		arr2 = new int[] { 2, 5, 8 };
		System.out.println(arr.length);//3
		System.out.println(arr[0]);//0
		arr[1]=100;
		System.out.println(arr[arr.length-1]);//0
	}
}


二、Collection

Collection是所有集合的顶级接口,List和Set 

集合提供了add(),remove(),以及迭代器遍历方法

三、Map

用key-value方式建立的查询表,其本质是Entry[]加LinkedList数据,用于快速查找元素的一种数据结构

HashMap的实现原理:传送门:http://blog.csdn.net/vking_wang/article/details/14166593



猜你喜欢

转载自blog.csdn.net/core_coder/article/details/51174675
今日推荐