---
title: "hashmap和treemap性能比较"
author: "ytrgmj"
date: "2012-04-07T16:11:19Z"
tags: []
categories: ["编程语言"]
slug: "hashmap-treemap"
draft: false
lastmod: "2012-04-07T16:11:19Z"
id: 1478063
url: "https://ytrgmj.iteye.com/blog/1478063"
---

周末在家测试了hashmap和treemap的性能，分别产生指定数目的随机数，然后依次放到不同的容器中，记录一下放之前和放之后的时间。然后再根据产生的随机数，在容器中中读一把，记录一下读之前和读之后的时间。 hashmap的测试代码如下： \[code="java"]List keys = new ArrayList(S\_Len); HashMap map = new HashMap(); { Random random = new Random(); for(int i=0;i