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

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 Tutorials/Questions & Answers:
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
Advertisements
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...(); } } } } If you want develop above program with HashMap read the words from console based... HashMap and search the words in file content. (adsbygoogle
how to count words in string using java
how to count words in string using java  how to count words in string...("Number of words are: "+count); } } Thanks   Hello, Try...[]=st.split(" "); System.out.println("Number of words are: "+arr.length
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
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
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
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
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
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
Count words in a string method?
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... = window.adsbygoogle || []).push({}); Enter string: hi how are you Number of words : 4
ModuleNotFoundError: No module named 'the-count-of-words'
ModuleNotFoundError: No module named 'the-count-of-words'  Hi, My... named 'the-count-of-words' How to remove the ModuleNotFoundError: No module named 'the-count-of-words' error? Thanks   Hi, In your
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
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
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
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
ModuleNotFoundError: No module named 'number-to-words'
ModuleNotFoundError: No module named 'number-to-words'  Hi, My... named 'number-to-words' How to remove the ModuleNotFoundError: No module named 'number-to-words' error? Thanks   Hi, In your python
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
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
Java file line count
Java file line count In the section, you will learn how to count the number... of the file. We have used counter here to detect the number of lines occurred... Exception { int count = 0; File f = new File("C:/data.txt"); Scanner input
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
Java count vowels
Java count vowels In this section you will learn how to count the number... and then you will get the number of vowels count. Description of code : In this code.... to console. Example  : A Code to count the number of vowel in a string
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
Java file number of lines
Java file number of lines In this section, you will learn how to count the number of lines from the given file. Description of code: Java has provide... counter here to detect the number of lines occurred in the file.  hasNextLine
Program to Find Cube Root of any Number without using built in function
Program to Find Cube Root of any Number without using built in function  Please help me in finding cube root of any number without using Built in function in java
Convert Number To Words
Convert Number To Words       In this example, We are going to convert number to words. Code... representing the number. Here is the code of this program: public 
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
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 program - convert words into numbers?
Java program - convert words into numbers?   convert words into numbers?   had no answer sir
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 (adsbygoogle = window.adsbygoogle || []).push({}); Output :- Software
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 (adsbygoogle = window.adsbygoogle || []).push({}); Output :- Software
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 (adsbygoogle = window.adsbygoogle || []).push({}); Output :- Software
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 (adsbygoogle = window.adsbygoogle || []).push({}); Output :- Software
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 (adsbygoogle = window.adsbygoogle || []).push({}); Output :- Software
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
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
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
ModuleNotFoundError: No module named 'odoo8-addon-base-bank-account-number-unique'
-unique'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odoo8-addon-base-bank-account-number-unique...-bank-account-number-unique' error? Thanks   Hi, In your
Count number of nodes
(struct node *p ) { int count=0; while (p != NULL) { count ++; p = p->link; } return(count); } void main() { int n; int x; struct node *start = NULL ; printf("Enter number of nodes to be created
How to store unique values in Java using Set?
the unique values. Here is the example program to store unique values in Java using...Store unique values in Java using Set interface In this section we... will show you how to store unique values in Java using Set? The Set interface
retrieve kv pairs using hashmap
retrieve kv pairs using hashmap  i want to retrieve k,v-pairs from a hashmap. the entrys are like this: a = 3,4 b = 5,6 and so on. i need combinations of these values. (adsbygoogle = window.adsbygoogle || []).push
hashmap
hashmap  write a program that shows the use of Hashmap class

Ads