Home Answers Viewqa Java-Beginners Program to count the number of unique words in a file using HashMap

 
 


v.lavanya
Program to count the number of unique words in a file using HashMap
0 Answer(s)      a year and a month ago
Posted in : Java Beginners

import java.io.File;
import java.io.FileNotFoundException;
import java.util.*; 
public class CountUniqueWords {

    public static void main(String args[]) throws FileNotFoundException { 

        File f = new File("C:/547647/word.txt");
        ArrayList arr=new ArrayList();
        HashMap<String, Integer> listOfWords = new HashMap<String, Integer>(); 
        Scanner in = new Scanner(f);
        int i=0;
        while(in.hasNext())
        {
        String s=in.next();
        //System.out.println(s);
        arr.add(s);
        }
        Iterator itr=arr.iterator();
        while(itr.hasNext())
        {i++;

            listOfWords.put((String) itr.next(), i);
            //System.out.println(listOfWords);
        }

        Set<Object> uniqueValues = new HashSet<Object>(listOfWords.values()); 

        System.out.println("The number of unique words: "+uniqueValues.size());



}
}
View Answers









Related Pages:
Program to count the number of unique words in a file using HashMap
Program to count the number of unique words in a file using HashMap  ...()); System.out.println("The number of unique words: "+uniqueValues.size...[]) throws FileNotFoundException { File f = new File("C:/547647/word
tO FIND UNIQUE WORDS IN A FILE USING HASHMAP
tO FIND UNIQUE WORDS IN A FILE USING HASHMAP  import java.util....())); } System.out.println("Number of unique words in file "+cc...() { // create a HashMap to store unique combination of words
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file
program to display frequency count of each word in a file using Hashmap, Hashset and streamtokenizer.plz help me out ..
program to display frequency count of each word in a file using Hashmap... above program with HashMap read the words from console based on key and value(ex... the words in file content.   Program : by HashSet and StringTokenizer
Java count words from file
by using the StringTokenizer class, we can easily count the number of words...Java count words from file In this section, you will learn how to determine the number of words present in the file. Explanation: Java has provides several
Java Word Count - Word Count Example in Java
some strings and program will count the number of characters and number of words... to count the number of lines, number of words and number of characters in the specified file. Program takes the file name as parameter and it counts the number
Example: Count Bad Words
Java NotesExample: Count Bad Words Your grandmother has learned to program... the grandchildren's email to make sure they aren't using any "bad" words. She doesn't know... program that just reads one line of text with a dialog box. It counts the number
Retrieve a list of words from a website and show a word count plus a specified number of most frequently occurring words
. print: the total number of words processed, the number of unique words, the N...Retrieve a list of words from a website and show a word count plus a specified...; Integer count; // number of occurrences WordPair(String word
how to count words in string using java
how to count words in string using java  how to count words in string...++; } System.out.println("Number of words are: "+count); } } Thanks   Hello... count=0; String arr[]=st.split(" "); System.out.println("Number
Count numbers of spaces and number of words from the input string
Count numbers of spaces and number of words from the input string Java In this section, you will learn how to count the number of spaces and words from... the number of spaces. Now, in order to count the number of words, we have splitted
Programming: Count Words - Dialog
Java NotesProgramming: Count Words - Dialog Description Write a program which counts the number of words in text the user enters. Assume that a word... words, and so is "test this". Only count blanks if the last
Exercise - Count Words
Java: Exercise - Count Words Problem Write a method which counts the number of words in a string. Assume that a word is defined as a sequence of letters... between words should only count if they include at least one blank so
JavaScript Count Words
and using the regular expression, determine the number of words and finally display...JavaScript Count Words In this section, you will learn how to count words... that will display the number of the words in the textbox as the user enter the words
Programming: Count Words - Dialog
Java NotesProgramming: Count Words - Dialog Description Write a program which counts the number of words in text the user enters. Assume that a word... error-prone1 Hints Blank counter. The number of words it the number
Count instances of each word
of the words preceded by the occurrence count. My program compiles and runs... number 1 of 1 program 2 test 2 that 1 the 1 this 1 to 1 total 1 using 1 verify 1...Count instances of each word  I am working on a Java Project
Count words in a string method?
count the length of arr which return the number of words in the inputted string...Count words in a string method?  How do you Count words in a string...(" "); System.out.println("Number of words : "+arr.length); }catch(IOException e
Count number of "*"
Count number of "*"  I have this code to count the number of * from a string entered. but I need to find it from an text file. Any idea? import...:"); String text = bf.readLine(); int count = 0; for (int i = 0; i
Exercise - Count Words
Java: Exercise - Count Words Problem Write a method which counts the number of words in a string. Assume that a word is defined as a sequence of letters... between words should only count if they include at least one blank so
Java HashMap - Java Tutorials
.style1 { text-align: center; } Hash Map The Map interface maps unique keys to value means it associate value to unique keys which you use to retrieve value at a later date. Some of the key points are : Using a key
Example - Read Words
Java Notes: Example - Read Words The program below reads a text file.../ReadWordsGUI.java // Purpose: Read a file and display all words in it. // Author... // Purpose: Read a file and display all words in it. // Author : Fred Swartz
Find number of words begin with the specified character
Count number of words begin with the specified character In this section, you will learn how to count the number of words that begin with the specified... with the input character. If found, counter will count the words. Here is the code
Java file line count
Java file line count In the section, you will learn how to count the number...("Number of Line: " + count); } } In this section, we have used data.txt file... till the end of the file. We have used counter here to detect the number
hashmap
hashmap  write a program that shows the use of Hashmap class
Collection : HashMap Example
Collection : HashMap Example This tutorial will help you in understanding of HashMap concept. HashMap : The java.util.HashMap class implements Map interface. It gives you an unsorted, unordered Map. It provides unique keys to each
column count using metadata
GET COLUMN COUNT USING "RESULTSETMETADATA"   In this program ,we will get column count using "resultsetmetadata ".Using resultset... = rs.getMetaData();     int NumOfCol=rsmd.getColumnCount();     System.out.println("Number
To Count The Elements in a XML File
To Count The Elements in a XML File       In this section, you will learn to count the element... Xerces Description of program: This program takes a file name from the console
Count number of characters in a column.
Count number of characters in a column.  I just need you suggestions. Am from Biology Back ground. I just need to find out number of characters in a column i.e, if i have a file with text in this manner ACGT GCTA GCTA i need
Convert Number To Words
Convert Number To Words       In this example, We are going to convert number to words. Code... the string representing the number. Here is the code of this program
Example - WordFrequency
; } /** Returns the number of unique, non-ignored words, in the source file(s.... } //============================================================= getWordCount /** Returns number of words in the soure file(s... to getWordFrequency. *@return Number of unique non-ignored source words
how to count unique and duplicate values from one table in mysql?
how to count unique and duplicate values from one table in mysql?  I have use EMP table.I want to count unique and duplicate records from emp table and how to use in java program
Map words to line number in text file and show occurence
Map words to line number in text file and show occurence  hi i want to Map words to line number in text file and show occurrence of word in java coding
display co-occurrence words in a file
display co-occurrence words in a file  how to write java program for counting co occurred words in the file
display co-occurrence words in a file
display co-occurrence words in a file  how to write java program for counting co occurred words in the file
Java Word Occurrence Example
many times words are repeated in a file. This example explains you that how you can count the occurrences of each word in a file. In this example we will use the HashMap for putting and getting the values. This program takes the file
Implementing a SoftReference based HashMap - Java Tutorial
. */ private final Map hash = new HashMap(); /** The number of "hard"... objects from the HashMap by looking them up using the SoftValue.key data member...Implementing a SoftReference based HashMap 2001-03-28 The Java Specialists
Breaking the String into Words
between the words. This program also counts the number of words present in the string... into separate words. This program takes a string from user and breaks... Breaking the String into Words     
Java count occurrence of number from array
Java count occurrence of number from array Here we have created an example that will count the occurrence of numbers and find the number which has... 6, only (0-6 ) are allowed. If a number is not within this range, program
Word Count
. To count it we are using countMatches() method... and "sub" is substring to be count.  The code of the program... Word Count      
Java Count Vowels
Java Count Vowels       In this program you will learn how to count vowels in a String. Here you... the number of vowels from that String. Description of the code: In the program code
A Program To Reverse Words In String in Java
A Program To Reverse Words In String in Java  A Program To Reverse Words In String in Java for example: Input:- Computer Software Output... Tell Me This Program.  Here is an example that reverse the words
Subset Tag (Control Tags) Example Using Count
Subset Tag (Control Tags) Example Using Count       In this section, we are going to describe the subset tag using the count parameter. The count parameter indicates the number of entries
program to display all words in the file in the sorted order without duplicates
program to display all words in the file in the sorted order without duplicates  I want a java program which accepts a file from user and displays all words in the file in the sorted order without duplicates
HashMap in Java
HashMap class is used to implement Map interface. The value of HashMap is stored using get() and put(). HashMap provides key-value access to data. HashMap is almost equal to HashTable, the only difference is that HashMap allows null
Hibernate criteria count.
Hibernate criteria count.  How do we count rows using criteria in hibernate?   Create hibernate configuration file (hibernate.cfg.xml... list = criteria.list(); System.out.println("Number of employee : "+list.get
Rows Count Example Using JDBC ResultSet
Rows Count Example Using  JDBC ResultSet: In this tutorial you can count the number of rows in the database table using ResultSet. Through this example... object using next() and find the number of rows as: rs.next
Java count frequency of words in the string
Java count frequency of words in the string. In this tutorial, you will learn how to count the occurrence of each word in the given string. String..., input validation, and file conversion. Here we are going to find the frequency
Count Vowels
Count Vowels   Read a string from the user, your program counts the number of vowels in the text and have it report a sum of each vowel found as well as the number of spaces. Make it in two classes
putting words to line number form a java file/test file and show occurrence
putting words to line number form a java file/test file and show occurrence  hi all i want putting words to line number form a java file and show occurrence but i cant use mapping method i can only use the LinkedList
Find the percentage of words which starts with a vowel in a file
Find the percentage of words which starts with a vowel in a file   Question: Find the percentage of words which starts with a vowel in a file. Ex: Input: Contents of File1- There is an endless loop in the program. Output: Vowel
Problem while using a HashMap for writing text ina RTF file. - Framework
Problem while using a HashMap for writing text ina RTF file.  Hi, I am trying to generate a RTF file using iText.jar, wherein I am taking... matched to the string then only write to the RTF file. Problem is Document writes

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.