一个字符串中出现次数最多的单词 java语言实现

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;


public class SubStringAppear 
{
	public static void main(String args[])
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=null;
		try {
			str = br.readLine();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		int a=0,b=0;
		ArrayList list=new ArrayList();
		int i,j;
		while(true)
		{
			for(i=b;i ite=list.iterator();
		while(ite.hasNext())
		{
			System.out.println(ite.next());
		}
		HashMap map=new HashMap();
		ite=list.iterator();
		while(ite.hasNext())
		{
			String s=ite.next();
			if(map.get(s)==null)
			{
				map.put(s, 1);
			}
			else
			{
				map.put(s, new Integer(map.get(s)+1));
			}
		}
		Collection col=map.values();
		Iterator io=col.iterator();
		int max=0;
		while(io.hasNext())
		{
			int k=io.next();
			if(max> set=map.entrySet();
		 Iterator> it=set.iterator();
		 while(it.hasNext())
		 {
			 Map.Entry entry=it.next();
			 if(entry.getValue()==max)
			 {
				 System.out.println("出现次数最多的单词为: "+entry.getValue()+"出现的次数为: "+max);
			 }
		 }
		
	}
}
//用java的迭代器和HashMap实现的

你可能感兴趣的:(java)