A Travel-Agent Case Study (Cont.)


Below gives some explanations for the previous program:
ArrayList<String> pathForMiles = new ArrayList<String>( );
ArrayList is a part of collection framework and is present in java.util package. It provides us dynamic arrays. It may be slower than standard arrays, but can be helpful in programs where intensive manipulation of the arrays is needed. This statement uses the method of generics, < >, to have the elements of a generic array become the type String. ArrayList provides many methods. For example,

  • add(E e) appends the specified element E to the end of the list.
  • contains(Object) returns true if this list contains the specified element.
  • get(int index) returns the element at the specified position in the list.
  • remove(int index) removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).
  • size( ) returns the number of elements in this list, i.e., the size of the list.
  • toArray(T[ ], a) returns an array containing all of the elements in this list in proper sequence (from first to last element).

assert data != null && data.length > 0 : "Failed precondition";
An assertion allows testing the correctness of any assumptions that have been made in the program. Assertion is achieved using the assert statement in Java. While executing assertion, it is believed to be true. If it fails, JVM throws an error named AssertionError.

airlineNames = lineFromFile.split( ", " );
The method split(String regex) has two variants and splits this string around matches of the given regular expression.



      Good things come to those who wait.