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



Home Answers Viewqa Java-Beginners program to display all words in the file in the sorted order without duplicates
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sowndarya sree
program to display all words in the file in the sorted order without duplicates
2 Answer(s)      3 years and 6 months ago
Posted in : Java Beginners


I want a java program which accepts a file from user and displays all words in the file in the sorted order without duplicates


Advertisement
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
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
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
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 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
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
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
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
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
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
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... + " words."); } } Output: File has 24 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...: In the program code given below, you will be asked to enter the file name first
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
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
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
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
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
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
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
Advertisements
 

 

 

DMCA.com