---
title: "报告ArrayList的一个错误，大家一起来研究下"
author: "finallyliuyu"
date: "2010-03-06T21:26:31Z"
tags: ["J#", "Lucene"]
categories: ["编程语言"]
slug: "arraylist"
draft: false
lastmod: "2010-03-06T21:26:31Z"
id: 609410
url: "https://finallyliuyu.iteye.com/blog/609410"
---

代码目的：计算一段文本中重复出现的词的个数。 分两种情况： 1.文本在内存中 2.文本在硬盘文件上 方案利用ArrayList 声明一个类 public class Entity { String word; float pValue; public Entity() { pValue=0; word=""; } } \[color=red]1.文本在内存中\[/color]主类中有以下代码 \[code="java"]String \[]words={"小","团圆","究竟","泄了","张爱玲","什么","秘密","2009年","04月","08日","09：56","天天","小","团圆","究竟","哈哈","张爱玲","全额","天涯","张爱玲"}; ArrayList enList=new ArrayList(); for(String w: words) { w=w.trim(); Entity en=new Entity(); en.word=w; en.pValue=1; enList.add(en); //System.out.println(w); } for(int i=0;i enList=new ArrayList(); for(String w: words) { w=w.trim(); Entity en=new Entity(); en.word=w; en.pValue=1; enList.add(en); //System.out.println(w); } for(int i=0;i