COMS W1004 Lecture 14: Dictionary

108 views5 pages
importjava.io.BufferedReader;
importjava.io.FileReader;
importjava.io.IOException;
importjava.util.ArrayList;
importjava.util.List;
public class WordLists {
static List<String>dictionaryList = new ArrayList<String>();
static List<String>arrList = new ArrayList<String>();
publicWordLists(String fileName) throws IOException {
String data = null;
BufferedReader input = new BufferedReader(new FileReader(fileName));
while((data=input.readLine()) != null) {
dictionaryList.add(data);
}
}
// This method returns an array of words of length n.
public static List<String>lengthN(int n) {
for(int i =0; i <dictionaryList.size(); i++) {
if(dictionaryList.get(i).length() == n) {
arrList.add(dictionaryList.get(i));
}
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in
}
System.out.println(arrList);
returnarrList;
}
//This method returns an array of words of length n beginning with the letter firstLetter
public static List<String>startsWith(int n, char firstLetter ) {
for(int i =0; i <dictionaryList.size(); i++) {
if(dictionaryList.get(i).length() == n &&dictionaryList.get(i).charAt(0) ==
firstLetter) {
arrList.add(dictionaryList.get(i));
}
}
System.out.println(arrList);
returnarrList;
}
//This method returns an array of words of length n containing the letter included but not
beginning with it.
public static List<String>containsLetter(int n, char included) {
String str = Character.toString(included);
for(int i =0; i <dictionaryList.size(); i++) {
if(dictionaryList.get(i).length() == n &&dictionaryList.get(i).charAt(0) != included
&&dictionaryList.get(i).contains(str)) {
arrList.add(dictionaryList.get(i));
}
}
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Importjava. io. bufferedreader; importjava. io. filereader; importjava. io. ioexception; importjava. util. arraylist; importjava. util. list; public class wordlists { static listdictionarylist = new arraylist(); static listarrlist = new arraylist(); publicwordlists(string filename) throws ioexception { Bufferedreader input = new bufferedreader(new filereader(filename)); while((data=input. readline()) != null) { dictionarylist. add(data); // this method returns an array of words of length n. public static listlengthn(int n) { for(int i =0; i startswith(int n, char firstletter ) { for(int i =0; i containsletter(int n, char included) { String str = character. tostring(included); for(int i =0; i

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions