Package com.xmlmind.util
Class StringList
- java.lang.Object
-
- com.xmlmind.util.StringList
-
public final class StringList extends Object
A collection of utility functions (static methods) operating on lists of Strings.What is called a list of Strings here is simply an array of Strings. Such array may not contain
nullelements.
-
-
Field Summary
Fields Modifier and Type Field Description static String[]EMPTY_LISTA ready-to-use empty list of Strings.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String[]append(String[] strings, String string)Inserts a String as last item of a list of Strings.static booleancontains(String[] strings, String string)Tests if liststringscontains Stringstring.static booleancontainsIgnoreCase(String[] strings, String string)Same ascontains(java.lang.String[], java.lang.String)but string comparison is case-insensitive.static intindexOf(String[] strings, String string)Searches Stringstringwithin liststrings.static String[]insertAt(String[] strings, String string, int index)Inserts a String inside a list of Strings.static String[]prepend(String[] strings, String string)Inserts a String as first item of a list of Strings.static String[]remove(String[] strings, String string)Removes a String from a list of Strings.static String[]removeAt(String[] strings, int index)Removes an item specified by its position from a list of Strings.
-
-
-
Field Detail
-
EMPTY_LIST
public static final String[] EMPTY_LIST
A ready-to-use empty list of Strings.
-
-
Method Detail
-
indexOf
public static int indexOf(String[] strings, String string)
Searches Stringstringwithin liststrings.- Parameters:
strings- the list to be searchedstring- the String to search for- Returns:
- the index of the searched string within list or -1 if not found
-
contains
public static boolean contains(String[] strings, String string)
Tests if liststringscontains Stringstring.- Parameters:
strings- the list to be searchedstring- the String to search for- Returns:
truethe string is found andfalseotherwise
-
containsIgnoreCase
public static boolean containsIgnoreCase(String[] strings, String string)
Same ascontains(java.lang.String[], java.lang.String)but string comparison is case-insensitive.
-
insertAt
public static String[] insertAt(String[] strings, String string, int index)
Inserts a String inside a list of Strings.- Parameters:
strings- the list where a String is to be insertedstring- the String to insertindex- the insertion index- Returns:
- a list containing all the items of list
stringsplus Stringstringinserted at positionindex
-
prepend
public static String[] prepend(String[] strings, String string)
Inserts a String as first item of a list of Strings.- Parameters:
strings- the list where a String is to be insertedstring- the String to insert- Returns:
- a list containing all the items of list
stringsplus Stringstringinserted at its beginning
-
append
public static String[] append(String[] strings, String string)
Inserts a String as last item of a list of Strings.- Parameters:
strings- the list where a String is to be insertedstring- the String to insert- Returns:
- a list containing all the items of list
stringsplus Stringstringinserted at its end
-
remove
public static String[] remove(String[] strings, String string)
Removes a String from a list of Strings.- Parameters:
strings- the list where a String is to be removedstring- the String to remove- Returns:
- a list containing all the items of list
stringsless Stringstringif such String is contained in the list; the original list otherwise
-
removeAt
public static String[] removeAt(String[] strings, int index)
Removes an item specified by its position from a list of Strings.- Parameters:
strings- the list where an item is to be removedindex- the position of the item to remove- Returns:
- a list containing all the items of list
stringsless the item at positionindex
-
-