Package dev.davwheat
Class StringTools
- java.lang.Object
-
- dev.davwheat.StringTools
-
public class StringTools extends java.lang.Object
A collection of utilities for modifying Strings.
-
-
Constructor Summary
Constructors Constructor Description StringTools()
-
Method Summary
Modifier and Type Method Description static java.lang.String
centreText(java.lang.String text, int width)
Takes a string as input, and a maximum length, then centres the text within that length.static java.util.ArrayList<java.lang.String>
centreText(java.util.List<java.lang.String> text, int width)
Takes a list of strings as input, and a maximum length, then centres the text within that length.static java.lang.String
concatenateListOfLines(java.util.List<java.lang.String> lines)
Joins an ArrayList of Strings into a single string, separated by new lines.static java.util.List<java.lang.String>
splitStringAtWhitespace(java.lang.String text, int width)
Takes a string, and wraps it to the maximum length provided, while adhering to whitespace location where possible.
-
-
-
Method Detail
-
centreText
public static java.util.ArrayList<java.lang.String> centreText(java.util.List<java.lang.String> text, int width)
Takes a list of strings as input, and a maximum length, then centres the text within that length.If there is an odd amount of spacing required, we favour extra spacing on the left.
- Parameters:
text
- input string to be centredwidth
- the maximum length per line- Returns:
- centred, possibly multi-lined, string
-
centreText
public static java.lang.String centreText(java.lang.String text, int width)
Takes a string as input, and a maximum length, then centres the text within that length.If there is an odd amount of spacing required, we favour extra spacing on the left.
If the input is longer than the width, nothing will be done.
- Parameters:
text
- input string to be centredwidth
- the maximum length per line- Returns:
- centred string
-
concatenateListOfLines
public static java.lang.String concatenateListOfLines(java.util.List<java.lang.String> lines)
Joins an ArrayList of Strings into a single string, separated by new lines.Preserves all whitespace on each line.
- Parameters:
lines
- list of strings- Returns:
- new-line delimited string
-
splitStringAtWhitespace
public static java.util.List<java.lang.String> splitStringAtWhitespace(java.lang.String text, int width)
Takes a string, and wraps it to the maximum length provided, while adhering to whitespace location where possible.- Parameters:
text
- Inputwidth
- Maximum length per line- Returns:
- Wrapped string
-
-