importjava.io.File;
importjava.io.FileWriter;
importjava.io.IOException;
importjava.util.ArrayList;
importjava.util.List;
publicclass${
privatestaticList<String>data=newArrayList<String>();
publicstaticvoidmain(String[]args){
try{
Stringstr="atihhhfughwedckgg";
//(1)用代碼實現統計有多少種字母,以及每個字母的個數,
test1(str);
System.out.println(data);
//(2)將查詢的數據存放到D盤根目錄下的Test文本文件下。
test2();
}catch(Exceptione){
e.printStackTrace();
}
}
privatestaticvoidtest1(Stringstr){
intlen=0;
Stringfst="";
while(str.length()>0){
len=str.length();
fst=str.substring(0,1);
str=str.replaceAll(fst,"");
data.add(fst+":"+(len-str.length()));
}
}
privatestaticvoidtest2()throwsIOException{
FileWriterfw=newFileWriter(newFile("d:/a.txt"));
for(Stringstr:data){
fw.write(str+" ");
}
fw.flush();
fw.close();
}
}