public final class StringList extends AbstractStringList
StringList objects can be constructed empty or they can be created using any of several static factory methods:
The tokenize() factory methods allow easy creation of StringLists via StringTokenizer. The repeat() static factory method creates a StringList that repeats a given String a given number of times.
The prepend() method adds a String to the beginning of the StringList. The removeLast() method pops a String off the end of the list. The sort() method sorts strings in the List using Collections.sort(). The class also inherits useful methods from AbstractStringList that include join() methods ala Perl and a toString() method which joins the list of strings with comma separators for easy viewing.
Constructor and Description |
---|
StringList()
Constructor.
|
StringList(int size)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int pos,
String string)
Adds the string to the stringlist at position pos.
|
void |
add(String string)
Adds a string to the back of this list.
|
void |
add(StringValue value)
Adds a string value to this list as a string.
|
boolean |
contains(String string) |
String |
get(int index)
Gets the string at the given index.
|
List<String> |
getList() |
IStringIterator |
iterator()
Returns a typesafe iterator over this collection of strings.
|
void |
prepend(String string)
Adds the given string to the front of the list.
|
void |
remove(int index)
Removes the string at the given index.
|
void |
removeLast()
Removes the last string in this list.
|
static StringList |
repeat(int count,
String string)
Returns a list of a string repeated a given number of times.
|
int |
size() |
void |
sort()
Sorts this string list alphabetically.
|
String[] |
toArray()
Converts this string list to a string array.
|
static StringList |
tokenize(String string)
Extracts tokens from a comma and space delimited string.
|
static StringList |
tokenize(String string,
String delimiters)
Extracts tokens from a delimited string.
|
int |
totalLength() |
static StringList |
valueOf(Collection<?> collection)
Converts a collection of objects into a list of string values by using the conversion methods
of the StringValue class.
|
static StringList |
valueOf(Object[] objects)
Converts an array of objects into a list of strings by using the object to string conversion
method of the StringValue class.
|
static StringList |
valueOf(String string)
Returns a string list with just one string in it.
|
static StringList |
valueOf(String[] array)
Converts a string array to a string list.
|
public StringList()
public StringList(int size)
size
- Number of elements to preallocatepublic static StringList repeat(int count, String string)
count
- The number of times to repeat the stringstring
- The string to repeatpublic static StringList tokenize(String string)
string
- The stringpublic static StringList tokenize(String string, String delimiters)
string
- The stringdelimiters
- The delimiterspublic static StringList valueOf(Collection<?> collection)
collection
- The collection to add as stringspublic static StringList valueOf(Object[] objects)
objects
- The objects to convertpublic static StringList valueOf(String string)
string
- The stringpublic static StringList valueOf(String[] array)
array
- The arraypublic void add(String string)
string
- String to addpublic void add(int pos, String string)
pos
- the position to add the string atstring
- the string to add.public void add(StringValue value)
value
- The value to addpublic boolean contains(String string)
string
- The string to look forpublic String get(int index)
get
in interface IStringSequence
get
in class AbstractStringList
index
- The indexIndexOutOfBoundsException
IStringSequence.get(int)
public IStringIterator iterator()
iterator
in interface IStringSequence
iterator
in class AbstractStringList
IStringSequence.iterator()
public void prepend(String string)
string
- The string to addpublic void remove(int index)
index
- The indexpublic void removeLast()
public int size()
size
in interface IStringSequence
size
in class AbstractStringList
IStringSequence.size()
public void sort()
public String[] toArray()
toArray
in class AbstractStringList
public int totalLength()
totalLength
in class AbstractStringList
Copyright © 2006–2022 Apache Software Foundation. All rights reserved.