Question: Write in Java Two words are anagrams if they contain the same letters in the same frequency. For instance, stale and least are anagrams of

Write in Java

Two words are anagrams if they contain the same letters in the same frequency. For instance, stale and least are anagrams of each other. A simple way to check this is to sort the characters in each word; if they get the same answer(in the example, we get aelst), the words are anagrams of each other. Write a Java method that uses the file dictionary.txt as the input and displays each word that is an anagram of each other in a group together.

Is there a way that i can have the words be read as input faster because it is taking a very long time for it to read in all the words from the dictionary.txt file. I have posted my java code below. If i could get help to have this read the input faster i would apprciate it. I have a very long list of words so if i could get it to read faster i would apprciate it

Code:

import java.io.File; import java.util.Arrays; import java.util.Scanner; public class Anagram { public static void main(String[] args)throws Exception { String filename = "/Users/blakethomas/Downloads/dictionary.txt"; System.out.println("The anagrams in group are as follows..."); anagramPrint(filename); } public static void anagramPrint(String filename) throws Exception { File file = new File(filename); Scanner sc = new Scanner(file); /** *Creating array of string to store all the values in it * */ String words[] = new String[100000]; int index=0; while (sc.hasNextLine()) { words[index] = sc.nextLine(); index++; } for(int i=0;i                                            

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!