/*  example of class ArrayList available in java.util package
    it is almost like arrays with most useful methods available.
    There are some disadvantages as well:
    1. The base type must be for Class or for reference type and not
       for primitive type such as int, float, or char.
    2. Without using the square bracket notations, it is notationally
       more awkward and less efficient.
    Now advantages:
    1. ArrayList can grow during program execution automatically.
    2. It is an example of a Generic Class which is a Generic programming
       with a type parameter that allows us to write code that can apply
       to any class.
       For example, we can define a class for a list of items of type T
       where T is a type parameter. We can then use this class with the class
       String plugged in for T for automatically get a class for a list of
       String objects. Similarly, we can plug in the class Double for T to get
       a list of Double objects.
    3. Some useful methods:
       a.  ArrayList#String> list new ArrayList#String>();
           // Creates an empty list named 'list' with the default capacity of 10.
       b.  ArrayList#String> list new ArrayList#String>(20);
           // Creates an empty list with the capacity of 20.
       c.  list.add ("Must be the first string of this list");
           list.add ("Here the second string is added to this list!!!");
           The one-argument add() must be used only to define a list element for the first time.
       cc. list.add (1, "New second string is to be inserted at index 1");
           Due to the insertion effect, all elements at index 1 and beyond will
           be shifted so that their respective indeces will be one higher.
           Simply insertion at index 1 and no element is removed.
       d.  list.set (1, "Second string of this list is being replaced);
           // At the same time, returns the previous contents at index 1.
           The index, 1, must be within the bounds, that is between 0 and
           list.size() or IndexOutOfBoundsException is thrown.
       e.  list.get (1)
           // returns the element (string in this example)
           The index must be within the bounds or IndexOutOfBoundsException
       f.  list.remove(1)
           // removes and returns the element at index 1.
           Also, the same exception as above may be thrown.
           Fringe Benefits: Each element with index 2 or above will have the
           index decreased by one. That is, all remaining elements will be
           contiguous after the removal.
       g.  list.removeRange(1,3)
           // Two elements at index 1 and 2, are removed. The these removals,
           all remaining elements will be rearranged to be contiguous.
       h.  public boolean remove (Object theElement)
           // The first occurrence of the specified list element will be
           removed and true will be returned to indicate that the given element
           was, in fact, found and removed. Otherwise, false will be returned.
           And, when found and removed, all remaining elements are rearranged
           to be contiguous.
       i.  public boolean contains (Object target)
           // returns true if the list has the specified target; otherwise
           returns false.
       j.  public int indexOf (Object target)
           // returns the index of the first element that is equal to the
           given target. Returns -1 if the target is not found.
       k.  public int lastIndexOf (Object target)
           // returns the index of the last element that is equal to the
           given target. Returns -1 if the target is not found.
       l.  public int size()
           // returns the number of elements in the calling ArrayList.
       m.  public boolean isEmpty()
           // returns true if the calling ArrayList is empty (that is,
           has size zero); otherwise returns false.
       n.  public Object clone()
           // Returns a shallow copy of the calling ArrayList.
           As a shallow copy is not an independent copy, subsequent changes
           to the clone may affect the calling object and vice versa.
       o.  public Object[] toArray()
           // returns an array containing all the elements on the list.
           Preserves the order of the elements.
       p.  public boolean equals (Object other)

*/

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class InputWordSorting
{
   public static void main(String[] args) throws FileNotFoundException
   {
      ArrayList#String> wordList = new ArrayList#String>();
    //just the default capacity of 10 that can automatically expand as need may arise.
      FileInputStream inputts = new FileInputStream (args[0]);
      String word;
      Scanner inputStream = new Scanner (inputts);   
      while (inputStream.hasNext())
        {
        word = inputStream.next();
        wordList.add (word);
        }
      Collections.sort (wordList);
      int count=0;
      for (String nextWord : wordList)
        {
        System.out.print ( nextWord + ":");
        count++;
        if (count%5 == 0) System.out.println();
        }       // end of for loop
      System.out.println ("\n\n..............END................\n");
   }    // end of main()
 }