Package collections

Class CollectionExample


  • public class CollectionExample
    extends java.lang.Object
    Example for the Collection interfaces.

    Wraps a collection and performs simple i/o.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Collection<java.lang.String> c
      Wrapped collection.
    • Constructor Summary

      Constructors 
      Constructor Description
      CollectionExample​(java.util.Collection<java.lang.String> c)
      Creates a new collection wrapper.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void dump()
      Dumps collection to the console.
      java.util.Collection getCollection()
      Returns wrapped collection.
      static void main​(java.lang.String[] args)
      Reads words from the file specified by the first command line argument and writes it to the console.
      int read​(java.lang.String file)
      Reads specified file word-by-word into the collection.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • c

        private final java.util.Collection<java.lang.String> c
        Wrapped collection.
    • Constructor Detail

      • CollectionExample

        public CollectionExample​(java.util.Collection<java.lang.String> c)
        Creates a new collection wrapper.
        Parameters:
        c - collection to wrap.
    • Method Detail

      • read

        public int read​(java.lang.String file)
                 throws java.io.IOException
        Reads specified file word-by-word into the collection.
        Parameters:
        file - file to read.
        Returns:
        number of words read.
        Throws:
        java.io.IOException - if an I/O error occurred.
      • dump

        public void dump()
        Dumps collection to the console.
      • getCollection

        public java.util.Collection getCollection()
        Returns wrapped collection.
        Returns:
        wrapped collection.
      • main

        public static void main​(java.lang.String[] args)
        Reads words from the file specified by the first command line argument and writes it to the console.
        Parameters:
        args - ignored