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

View Answers

May 27, 2011 at 4:44 PM

import java.io.*;
import java.util.*;

class DisplayFiledataInSortedOrder 
{
    public static void main(String[] args) throws Exception
    {
        Scanner input=new Scanner(System.in);
        System.out.println("Enter File name with path: ");
        String filename=input.next();
        File f=new File(filename);
        BufferedReader br=new BufferedReader(new FileReader(f));
        StringBuffer buffer=new StringBuffer();
        String str;
        while((str=br.readLine())!=null){
        buffer.append(str);
        buffer.append(" ");
        }
        ArrayList<String> list=new ArrayList<String>();
        StringTokenizer st = new StringTokenizer(buffer.toString().toLowerCase());
                while(st.hasMoreTokens()) {
                        String s = st.nextToken();
                        list.add(s);
                }
        HashSet<String> set = new HashSet<String>(list);
        List<String> arrayList = new ArrayList<String>(set);
        Collections.sort(arrayList);
        for (Object ob : arrayList)
        System.out.println(ob.toString());
    }
}

November 2, 2012 at 10:13 PM

Hi, tnx for the awesome code.How different would it be if we wanted to load from a tokenized HTML file?Thank you









Related Tutorials/Questions & Answers:
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
Display non-duplicate words from file
Display non-duplicate words from file In this tutorial, you will learn how to read a text file and display non-duplicate words in ascending order. The given... object is then passed to StringTokenizer which broke the text of file into words
Advertisements
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
display all words containing the letter which i gave as input...
display all words containing the letter which i gave as input...  If i enter any character,it have to display the names which having that character..write a program using java example(output) Enter any character: a Names: Abi
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
Display Sorted data in TextArea
all the file data in a sorted way into the text area according to the id...Display Sorted data in TextArea By sorting, you can arrange the data into meaningful order so that you can analyze it more effectively. Here we have one file
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  ...[]) throws FileNotFoundException { File f = new File("C:/547647/word...()); System.out.println("The number of unique words: "+uniqueValues.size
Arrange the sentences in alphabetical order of words Java
Arrange the sentences in alphabetical order of words In Java Program In this section, we are going to sort the order of words in all the specified sentences... the sentences. Now in order to split the words of each sentence, we have again
without writing web.xml file we can write servlet program
without writing web.xml file we can write servlet program  Sir Morning... Sir I have one Question "without writing web.xml file we can write servlet program". if yes which way? if no why? but without use Annotation........ Plz
Program to read the text from a file and display it on a JFrame.
Program to read the text from a file and display it on a JFrame.  import javax.swing.*; import java.io.*; import java.lang.*; import java.awt.*; class MegaViewer1 extends JFrame { JTabbedPane jtp1=new JTabbedPane
Breaking a string into words without using StringTokenizer
Breaking a string into words without using StringTokenizer  how can we Break a string into words without using StringTokenizer ??   The given code convert the string into words. import java.util.*; class StringExample
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
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... Tell Me This Program.  Here is an example that reverse the words
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... the words in file content.   Program : by HashSet and StringTokenizer...) { System.out.println("Enter word to search in given file(to stop words
Java Display File-Extension
Java Display File-Extension       In this program you will learn how to display the file extension of the file. Here you will be asked to enter the file name
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
java program to convert decimal in words
java program to convert decimal in words  write a java program to convert a decimal no. in words.Ex: give input as 12 output must be twelve
display repeated lines in a file
display repeated lines in a file  i want a java program that accepts file from user and displays the repeated lines in a file
Java count words from file
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...++; } System.out.println("File has " + count + " words."); } } Output:ADS_TO_REPLACE_3
Upload file without brouse button
Upload file without brouse button  Hi i want to upload 7 files without using browse button . I am using jscript to get the files and to view the files (.jpeg) .But I am not able to enter that address into file field can any body
xml file display - XML
code to display the above xml file in tree structure where...xml file display   - - - - ADL SCORM CAM 1.3 - - session3 - Online Instructional Strategies that Affect Learner
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
Program to check whether two given words pronouncing same or not?
Program to check whether two given words pronouncing same or not?  Program to check whether two given words pronouncing same or not? example: raju and rajoo pronouncing same please help me out
svg file reading and display
svg file reading and display  i want a sample program for reading and displaying the content of a svg file
to write a program to display the employee details..
to write a program to display the employee details..  To dipslay... running this program the new window has to be opened asking us to enter all...   not this one actually i wnat a very small program that displays all
How to display a file for 24 hours?
How to display a file for 24 hours?  How to display a file for 24 hours
How to Write to a File in Java without overwriting
Learn how to Write to a File in Java without overwriting in your Java program This tutorial teaches you how to write to a file in Java without overwriting... which already contains the data and our program will write to this file without
ModuleNotFoundError: No module named 'duplicates'
ModuleNotFoundError: No module named 'duplicates'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'duplicates' How to remove the ModuleNotFoundError: No module named '
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
without ;
without ;  can u give me an example of a program without
without ;
without ;  can u give me an example of a program without
how to display pdf file on browser
how to display pdf file on browser   In my project i have created one pdf file(by pdfwriter) into my local mechine . after that it need to display in browser as a pdf file . but in jsp i can't display by iframe tag can anyone
display all the values on next page
display all the values on next page  i am inserting values in the database through textboxes and dropboxes, when i am clicking on submit button those... when i return on first page it should display my selected values in textbox
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
program to display the first ten terms of the series
program to display the first ten terms of the series  Write a program to display the first ten terms of the following series : 1) 1,-3,5,-7,9..... 2) 3,6,12,24..... 3) 2,5,10,17....... 4) 0,1,2,3,6............ 5) 0,3,8,15
Connect a linux machine from linux using java program without password
Connect a linux machine from linux using java program without password  Connect a linux machine from linux using java program without password. Can anyone help me
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
ModuleNotFoundError: No module named 'is-sorted'
ModuleNotFoundError: No module named 'is-sorted'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'is-sorted' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'sorted'
ModuleNotFoundError: No module named 'sorted'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'sorted' How to remove the ModuleNotFoundError: No module named 'sorted'
ModuleNotFoundError: No module named 'is-sorted'
ModuleNotFoundError: No module named 'is-sorted'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'is-sorted' How to remove the ModuleNotFoundError: No module named '
How to display a record containing 30 fields in jsp without scrolling the page horizontally?
How to display a record containing 30 fields in jsp without scrolling the page horizontally?  I want to display records containing 30 fields in a table row.Is it possible in jsp without scrolling the page horizontally
ModuleNotFoundError: No module named 'find-duplicates'
ModuleNotFoundError: No module named 'find-duplicates'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'find-duplicates' How to remove the ModuleNotFoundError: No module named
Alphabetically sorting order
sorted order   Hi Friend, Try the following code: import...(st); } System.out.println("ArrayList Elements in Sorted order...Alphabetically sorting order  Write a java program that takes a list
Program to display palindrome numbers between some range
Program to display palindrome numbers between some range  Hi!I want a java program to display palindrome numbers between 100 to 1000.can you please explain me the logic with an example   import java.util.*; public

Ads