Class AbstractStringList

  • All Implemented Interfaces:
    Serializable, IStringSequence
    Direct Known Subclasses:
    StringList

    public abstract class AbstractStringList
    extends Object
    implements IStringSequence, Serializable
    An abstract base class for string list implementations. Besides having an implementation for IStringSequence (iterator(), get(int index) and size()), an AbstractStringList can be converted to a String array or a List of Strings.

    The total length of all Strings in the list can be determined by calling totalLength().

    Strings or a subset of Strings in the list can be formatted using three join() methods:

    • join(String) Joins strings together using a given separator
    • join() Joins Strings using comma as a separator
    • join(int first, int last, String) Joins a sublist of strings using a given separator
    Author:
    Jonathan Locke
    See Also:
    Serialized Form
    • Method Detail

      • toArray

        public String[] toArray()
        Returns this String sequence as an array of Strings. Subclasses may provide a more efficient implementation than the one provided here.
        Returns:
        An array containing exactly this sequence of Strings
      • toList

        public final List<StringtoList()
        Returns this String sequence as an array of Strings. Subclasses may provide a more efficient implementation than the one provided here.
        Returns:
        An array containing exactly this sequence of Strings
      • totalLength

        public int totalLength()
        Returns:
        The total length of all Strings in this sequence.
      • join

        public final String join()
        Joins this sequence of strings using a comma separator. For example, if this sequence contains [1 2 3], the result of calling this method will be "1, 2, 3".
        Returns:
        The joined String
      • join

        public final String join​(String separator)
        Joins this sequence of strings using a separator
        Parameters:
        separator - The separator to use
        Returns:
        The joined String
      • join

        public final String join​(int first,
                                 int last,
                                 String separator)
        Joins this sequence of strings from first index to last using a separator
        Parameters:
        first - The first index to use, inclusive
        last - The last index to use, exclusive
        separator - The separator to use
        Returns:
        The joined String
      • toString

        public String toString()
        Converts this object to a string representation
        Overrides:
        toString in class Object
        Returns:
        String version of this object