title: How do you use an array list in multiple classes?
body: <p>I want to store the input in my dictionary class so that I can search the words within this class. But I also need to use the array in other classes. Does anyone have an idea of how I can add input to my Dictionary() constructor?</p>
  
  <p>Does anyone have an idea of how to fix this??</p>
  
  <p>Thank you so much in advance!!!!</p>
  
  <pre><code>public class Dictionary {
    // Private data fields
    public ArrayList&lt;String&gt; dict;
  
    Dictionary() {
      dict = new ArrayList&lt;String&gt;();
  
    }
  
    public void add (String s){
      dict.add(s);
    }
  
    public int size (){
      return dict.size();
    }
  
    public String get(int i) {
      return dict.get(i);
    }
  
    public ArrayList&lt;String&gt; getList(){
      return dict;
    }
  
    public static void main(String[] args) throws IOException {
      if (args.length &lt; 1) {
        System.out.print("Must have a file.");
        System.exit(1);
      }
  
      try {
        File dictionaryFile = new File(args[0]);
  
        Scanner fin = new Scanner(dictionaryFile);
  
        System.out.println(dictionaryFile.getAbsolutePath());
  
        if (!dictionaryFile.exists()) {
          System.out.println("Dictionary " + args[0] + "does not exist");
        }
  
        else if (!dictionaryFile.canRead()) {
          System.out
              .println("Dictionary " + args[0] + " cannot be read.");
        }
        Dictionary dict = new Dictionary();
        while (fin.hasNext()) {
          dict.add(fin.nextLine());
        }
  
        for (int i = 0; i &lt; dict.size(); i++) {
          System.out.println(dict.get(i));
        }
  
      } catch (FileNotFoundException e) {
        System.out.println("No such file found " + args[0]);
      }
   }
  }
  
  /**
   *This is the class I want to reference the array in 
   */
  public class FindWords {
  
    public static void main(String[] args) {
      Dictionary dictionary = new Dictionary();
      System.out.print(dictionary.getList());
  
    }
  }
  </code></pre>