我做到打印文件里面的emial地址
下一步我要做的是 把这些emial
比较判断 判断email重复 重复2次的email放到 一起 重复3次的email放到一起。
该怎么做?FileWriter fw;
File file = new File("D:/email.txt");
FileReader in = new FileReader(file);
BufferedReader bufin = new BufferedReader(in);
String ttt = "";
while((ttt=bufin.readLine())!=null){
System.out.println( ttt );
}打印结果是这些email地址
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
下一步我要做的是 把这些emial
比较判断 判断email重复 重复2次的email放到 一起 重复3次的email放到一起。
该怎么做?FileWriter fw;
File file = new File("D:/email.txt");
FileReader in = new FileReader(file);
BufferedReader bufin = new BufferedReader(in);
String ttt = "";
while((ttt=bufin.readLine())!=null){
System.out.println( ttt );
}打印结果是这些email地址
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
楼主【wkdgofyd0312】截止到2008-06-25 16:49:54的历史汇总数据(不包括此帖):
发帖数:5 发帖分:100
结贴数:1 结贴分:20
未结数:4 未结分:80
结贴率:20.00 % 结分率:20.00 %
楼主该结一些帖子了
用map写一个方法吧,用email做key,value为找到的次数,
方法压数据时做一个判断,当存在给定的key时,value+1
import java.util.Map;public class Test_Map{
public static void do1(){
String str="1,2,3,4,5,6,7,8,9,4,5,8,5,6,6,6,1";
Map m=new Hashtable();
String[] a=str.split(",");
if(a!=null){
for(int i=0;i<a.length;i++){
if(m.get(a[i])!=null){
int s=-1;
try{s=Integer.parseInt(m.get(a[i])+"");}catch(Exception e){}
m.put(a[i], s+1);
}
else{
m.put(a[i], 1);
}
}
}
for(int i=0;i<m.size();i++){
System.out.println(a[i]+"##"+m.get(a[i]));
}
}
public static void main(String[] args){
do1();
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;public class TestTg {
private List list = new ArrayList(); public static void main(String[] args) throws Exception {
FileWriter fw;
File file = new File("D:/email.txt");
FileReader in = new FileReader(file);
BufferedReader bufin = new BufferedReader(in);
HashMap map = new HashMap();
String ttt = "";
String sList = "";
int count = 0;
TestTg tg = new TestTg();
while ((sList = bufin.readLine()) != null) {
tg.list.add(sList); }
for (int i = 0; i < tg.list.size(); i++) {
int temp = tg.check((String) tg.list.get(i));
map.put(tg.list.get(i), Integer.valueOf(temp));//key为email,value为次数 }//数据存入map
Iterator iterator = map.keySet().iterator();
while (iterator.hasNext()) { // 遍历map
Object key = iterator.next();
Object value = map.get(key);
System.out.println("Email---" + key + " 出现的次数-- " + value);
}
} public int check(String t) {
int count = 0;
for (int i = 0; i < list.size(); i++) {
if (t.equals((String) list.get(i)))
count++;
}
return count;
}}