|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.marringtons.string.Strings
This is a class of String static helper methods providing String testing and manipulation methods.
| Method Summary | |
static boolean |
isEmpty(String string)
Return true if string is null or has no characters. |
static boolean |
isNotEmpty(String string)
Return true if string is not null or empty. |
static String |
join(ArrayList parts,
String with)
Join an ArrayList of strings into a single string, separating elements with the specified string. |
static String |
join(String[] parts)
Join an array of strings into a single string, separating elements with comma space. |
static String |
join(String[] parts,
String with)
Join an array of strings into a single string, separating elements with the specified string. |
static String |
join(String[] parts,
String with,
int from)
Join an array of strings into a single string, separating elements with the specified string. |
static String |
join(String[] parts,
String with,
int from,
int upTo)
Join an array of strings into a single string, separating elements with the specified string. |
static String |
remove(String from,
int start,
int charactersToRemove)
Remove a portion of a string given the starting point and the number of character. |
static String |
remove(String from,
String toRemove)
Remove the first occurrence of one string in another returning the portions both before and after. |
static void |
sortDescendingByLength(String[] strings)
Sort an array of strings by length - longest first. |
static String[] |
split(String source)
Split a comma separator string into an array of strings. |
static String[] |
splitJava(String qualifiedName)
Split a Java qualified name (package.package.Class.field) into an array of strings. |
static String[] |
toArray(Collection collection)
It is common to collect strings in an ArrayList but need an array to return. |
static String[] |
toArray(Matcher matcher)
Create an array of strings from the return groups of a pattern match. |
static String |
toString(Object object)
Using toString on an object will fail if the object is null - but this static method won't. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
public static boolean isNotEmpty(String string)
if (Strings.isNotEmpty( myAnswer)) { System.out.println( "answered");
string - to check for content
public static boolean isEmpty(String string)
if (Strings.isEmpty( myAnswer)) return;
string - to check for content
public static String[] split(String source)
String[] parts = Strings.split( "ab, cd, ef"); parts[0].equals( "ab"); parts[1].equals( "cd"); parts[2].equals( "ef");
source - string to split
public static String[] splitJava(String qualifiedName)
qualifiedName - Java name to split.
public static String join(String[] parts)
String[] parts = { "ab", "cd", "ef" };
Strings.join( parts).equals( "ab, cd, ef");
parts - array of elements
public static String join(String[] parts,
String with)
String[] parts = { "ab", "cd", "ef" };
Strings.join( parts, " ").equals( "ab cd ef");
parts - array of elementswith - string to separate elements in the result
public static String join(String[] parts,
String with,
int from)
String[] parts = { "ab", "cd", "ef" };
Strings.join( parts, " ", 1).equals( "cd ef");
parts - array of elementswith - string to separate elements in the resultfrom - starting point in array (1 to skip first element)
public static String join(String[] parts,
String with,
int from,
int upTo)
String[] parts = { "ab", "cd", "ef", "gh" };
Strings.join( parts, " ", 1, parts.length - 1).equals( "cd ef");
parts - array of elementswith - string to separate elements in the resultfrom - starting point in array (1 to skip first element)upTo - Index to join up to but not including
public static String join(ArrayList parts,
String with)
parts - array of elementswith - string to separate elements in the result
public static String[] toArray(Collection collection)
collection - of String to turn into an Array.
public static String[] toArray(Matcher matcher)
matcher - from a pattern match.
Matcherpublic static void sortDescendingByLength(String[] strings)
strings - public static String toString(Object object)
object -
public static String remove(String from,
String toRemove)
from - String to have a section removed from.toRemove - String to remove from larger whole.
public static String remove(String from,
int start,
int charactersToRemove)
from - String to have a section removed from.start - Start position for the piece to cut out.charactersToRemove - Characters to remove.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||