
正文
java代码查重复 java查询重复字符串
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java检查每行重复的单词
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
public class Test {
public static void main(String[] args) throws IOException {
String file = "src.txt";
BufferedReader br = new BufferedReader(new FileReader(file));
String content = null;
final Integer one = new Integer(1);
int lineNumber = 1;
while((content = br.readLine()) != null){
String[] ary = content.trim().split("\\s+");
HashMapString, Integer map = new HashMapString, Integer();
for(int i = 0; i ary.length; i++){
if(map.containsKey(ary[i])){
map.put(ary[i], new Integer(map.get(ary[i]).intValue() + 1));
}else{
map.put(ary[i], one);
}
}
for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
String word = (String) iter.next();
int count = map.get(word).intValue();
if(count 1){
StringBuilder sb = new StringBuilder("The line ");
sb.append(lineNumber).append(": ");
for(int i = 1; i = count; i++){
sb.append(word).append(" ");
}
System.out.println(sb.toString());
}
}
lineNumber++;
}
}
}
-----------------------测试
源文件
I am am a student
This This is a good place place
--------测试结果
e line 1: am am
The line 2: This This
The line 2: place place
相关问答
Q1: java程序,找出文件中的重复数据数据。
你声明的String数组,在你 new 的时候,里面的所有元素都为 null,所以你在使用 equals 方法的时候一定要注意 a[i] 是不是等于 null 呢,你的程序中缺少这个判断
Q2: JAVA中判断重复
The method selectBookInfo() in the type Dao is not applicable for the arguments (String)
这个selectBookInfo() 方法声明中 没有arguments (String) 这个参数
即没有这个方法selectBookInfo(String arguments )
Q3: java100万条数据怎么查出重复
把数据表增加索引,提高查询效率,把数据排好序,测试查询速度,使用临时表保存排序好的数据,经过测试,处理插入100w条数据大概413秒,7分钟。
关于java代码查重复和java查询重复字符串的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






