Code
Map<String, Integer> wordMap = new HashMap<String, Integer>( );
try {
FileReader file = new FileReader( new File( "book.txt" ) );
BufferedReader br = new BufferedReader( file );
String temp = br.readLine( );
while ( temp != null ) {
String[] words = temp.split( " " );
for ( String word : words ) {
int count = 1;
if ( word.trim( ).length( ) == 0 ) {
continue;
}
if ( wordMap.get( word ) != null ) {
count = wordMap.get( word );
count++;
}
wordMap.put( word, count );
}
temp = br.readLine( );
}
}
catch ( Exception e ) {
}
System.out.println( wordMap.get( "the" ) );
This post was edited by labatymo on Dec 30 2013 09:25am