---
title: "java 常用的数据结构的迭代"
author: "i_coding"
date: "2011-05-19T16:25:15Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2011-05-19T16:25:15Z"
id: 1050449
url: "https://i-coding.iteye.com/blog/1050449"
---

ArrayList 底层是由数组实现 高查找 低修改 
LinkedList 底层是链表结构 低查找 高修改

迭代程序:
List ls = new LinkedList();
		String a = &quot;a&quot;;
		String b = &quot;b&quot;;
		ls.add(a);
		ls.add(b);
		Iterator it = ls.iterator();
		while (it.hasNext()) {
			System.out.println(&quot;LinkedList:&quot; + it.next());
		}

		List as = new ArrayList();
		as.add(&quot;c&quot;);
		as.add(&quot;d&quot;);
		Iterator it1 = as.listIterator();

		while (it1.hasNext()) {
			System.out.println(&quot;ArrayList中的值:&quot; + it1.next());
		}

		Map map = new HashMap();
		map.put(&quot;name&quot;, &quot;lwang&quot;);
		map.put(&quot;age&quot;, &quot;24&quot;);
		map.put(&quot;sex&quot;, &quot;男&quot;);
		map.put(&quot;email&quot;, &quot;234@qq.com&quot;);
		Set set = new HashSet();
		Set set2 = new HashSet();
		set = map.keySet();//
		Iterator it2 = set.iterator();
		while (it2.hasNext()) {
			String key = (String) it2.next();
			System.out.println(&quot;map的键值:&quot; + key);

			set2.add(map.get(key));//
		}

		Iterator it3 = set2.iterator();
		while (it3.hasNext()) {
			System.out.println(&quot;map中的值:&quot; + it3.next());
		}