I'm scanning my text and I want to add them into array list, but it is not easy. I want each word store from arrayList of a to z which is arrayList size is 26. Example:
arrayList a store string array of: an, and, apple, ...
arrayList b store string array of: be, become, became....
.
.
.
arrayList z store string array of: zero, zone...
In my class, I create:
private static ArrayList<String[]> words = new ArrayList<String[]>(26); // to store all words
In main, I do while loop to get each words and store in words array,
please help me out to get it correctly and what is the easier way to do this problem. Here is my code. Thank
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.LinkedList; import java.util.Scanner; public class BinaryTree { private static ArrayList<String[]> words = new ArrayList<String[]>(26); public Node root; public void addNode(int key, String name) { Node newNode = new Node(key, name); if (root == null) { root = newNode; } else { Node focusNode = root; Node parent; while (true) { parent = focusNode; if (key <focusNode.key) { focusNode = focusNode.leftChild; if (focusNode == null) { parent.leftChild = newNode; return; } } else { focusNode = focusNode.rightChild; if (focusNode == null) { parent.rightChild = newNode; return; } } } } } public void inOrderTraverseTree(Node focusNode){ if (focusNode != null) { inOrderTraverseTree(focusNode.leftChild); System.out.println(focusNode); inOrderTraverseTree(focusNode.rightChild); } } // public void insertBack(String data){ // // } public static void main(String[] args) throws FileNotFoundException { // String[] eachWord = new String[26]; // BinaryTree theTree = new BinaryTree(); // theTree.addNode(key, name); Scanner scan = new Scanner(new File("concordance.txt")); int i = 1; while(scan.hasNext()) { String nextToken = scan.next(); if (nextToken.equalsIgnoreCase("a")) { // how did I add from a to z to arrayList??? } i++; } // System.out.print(l.showList()); } }