public final class StringUtils extends Object
Modifier and Type | Method and Description |
---|---|
static <T> String |
conjoin(String sep,
Collection<T> objects)
Concatenate all objects in a collection with the given separator between each.
|
static <T> String |
conjoin(String separator,
Collection<T> objects,
int max)
Concatenate the string representation of a maximum number of objects in a collection with a given separator
between them.
|
static String |
conjoin(String sep,
String... strings)
Concatenate all strings in a collection with the given separator between each.
|
static String |
formatDate(long millis)
Formats the given date (as elapsed milliseconds) using the default format 'yyyy/MM/dd HH:mm:ss'.
|
static String |
formatDate(long millis,
String format)
Formats the given date (as elapsed milliseconds) using the provided format pattern.
|
static String |
formatDuration(long seconds)
Formats a duration in seconds as a string of the form "3d 04:12:56".
|
static String |
formatNumber(double number)
Formats a number, as a decimal number with at most 2 digits.
|
static String |
formatNumber(long number)
Formats a number, as a decimal number with at most 2 digits.
|
static String |
formatPercentage(double percentage)
Formats a numeric percentage, as a decimal number with at most 2 digits.
|
static String |
formatPercentage(long percentage)
Formats a numeric percentage, as a decimal number with at most 2 digits.
|
static String |
makeEllipsis(String orgString,
int maxLength)
Generate a ellipsis of orgString.
|
static List<Integer> |
parseIntList(String[] stringArray)
Change all Strings to Integers.
|
static String |
repeat(String s,
int n)
Repeat the string n times.
|
static String |
replace(String sentence,
String oldString,
String newString)
Replace all occurrences of oldString with newString in a string.
|
static String |
splitStringForce(String input,
int maxLineLength)
Given a multi-line input string, this method splits the string so that no line has length greater than
maxLineLength.
|
static String |
splitStringOnWhitespace(String input,
int lineLength)
Given an input String, this method splits the String with newlines into a multiline String with line-lengths
approximately lineLength.
|
static String |
surjoin(List<String> strings,
String pre,
String post)
Concatenate all strings in a collection, with the fixed strings appended and prepended to each.
|
public static String replace(String sentence, String oldString, String newString)
sentence
- the string, where all occurrences of oldString are to be replaced with newString.oldString
- the oldString.newString
- the newString.public static <T> String conjoin(String sep, Collection<T> objects)
T
- The type of objects to conjoin.sep
- A string to separate the list items.objects
- A collection of object to concatenate as a string.public static <T> String conjoin(String separator, Collection<T> objects, int max) throws ArgumentNotValid
T
- The type of collection.separator
- The string to separate the entries in the collection with. This is allowed to be the empty
string.objects
- The collection to have the string representation of its entries concatenated.max
- The maximum number of objects in the collection to concatenate. If this number is 0 or below only the
first entry in the collection is returned.ArgumentNotValid
- If the separator or the objects are null.public static String conjoin(String sep, String... strings)
sep
- A string to separate the list items.strings
- An array of strings to concatenate.public static String surjoin(List<String> strings, String pre, String post)
strings
- A list of strings to join up.pre
- A string that will be put in front of each string in the list.post
- A string that will be put after each string in the list.public static String repeat(String s, int n)
s
- A string to repeat.n
- How many times to repeat it.ArgumentNotValid
- if a negative amount is specified.public static List<Integer> parseIntList(String[] stringArray)
stringArray
- the given array of Strings to convert.public static String makeEllipsis(String orgString, int maxLength)
orgString
- the original string.maxLength
- the maximum length of the string before ellipsing it.public static String formatDuration(long seconds)
seconds
- A duration in secondspublic static String formatPercentage(double percentage)
percentage
- the numeric percentage to format.public static String formatPercentage(long percentage)
percentage
- the numeric percentage to format.public static String formatNumber(double number)
number
- the number to format.public static String formatNumber(long number)
number
- the number to format.public static String formatDate(long millis)
millis
- the datepublic static String formatDate(long millis, String format)
millis
- the dateformat
- the format pattern SimpleDateFormat
public static String splitStringOnWhitespace(String input, int lineLength)
input
- the input String.lineLength
- the desired line length.ArgumentNotValid
- if the input is null or the lineLength is not positivepublic static String splitStringForce(String input, int maxLineLength)
input
- the input String.maxLineLength
- the maximum permitted line length.ArgumentNotValid
- if input is null or maxLineLength is non-positiveCopyright © 2005–2015 The Royal Danish Library, the Danish State and University Library, the National Library of France and the Austrian National Library.. All rights reserved.