Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


v.lavanya
Program to count the number of unique words in a file using HashMap
0 Answer(s)      2 years and 8 months 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());



}
}

Advertisement
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... 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
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
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
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
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
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
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
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
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 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
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
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
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 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 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... have used counter here to detect the number of lines occurred 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 Output :- Software Computer
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 :- Software Computer
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 :- Software Computer
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 :- Software Computer
 

 

 

DMCA.com