Java Utililty Methods String Format

List of utility methods to do String Format

Description

The list of methods to do String Format are organized into topic(s).

Method

StringformatDescriptors(String descriptorString)
format Descriptors
StringBuilder formattedDescriptors = new StringBuilder();
String verkett = "";
String[] tokens = descriptorString.split(",|\\|");
Arrays.sort(tokens);
for (String token : tokens) {
    if (!token.endsWith("Descriptor")) {
        continue;
    token.substring(0, token.length() - 10);
    if (token.length() == 0) {
        continue;
    formattedDescriptors.append(verkett);
    formattedDescriptors.append(token);
    verkett = "<br>";
return formattedDescriptors.toString();
StringformatError(String errorMsg)
Format error message.
StringBuilder newErrMsg = new StringBuilder();
errorMsg = errorMsg.replaceAll("\n", "\n\t    ");
List<String> msgParts = Arrays.asList(errorMsg.split("\n"));
for (String msg : msgParts) {
    if (msgParts.indexOf(msg) != 0 && !msg.equals("\t    ")) {
        msg = "\t    \t" + msg.trim();
    if (!msg.equals("\t    ")) {
...
StringformatJson(String json)
format Json
if (json == null || json.trim().length() == 0) {
    return null;
int fixedLenth = 0;
ArrayList<String> tokenList = new ArrayList<String>();
    String jsonTemp = json;
    while (jsonTemp.length() > 0) {
...
ListformatLore(String str)
format Lore
final int lineLength = 36;
List<String> list = new ArrayList<>();
String current = "";
for (String s : str.split(" ")) {
    if (current.length() + s.trim().length() + 1 > lineLength) {
        list.add(current);
        current = "";
    } else if (!current.isEmpty()) {
...
StringformatMailtoLink(String emailAddress)
This is to take an email address and convert it to a link.
if (emailAddress == null || emailAddress.isEmpty()) {
    return "";
} else {
    return "<a href=\"mailto:" + encode(emailAddress) + "\" target=\"_blank\">" + encode(emailAddress)
            + "</a>";
StringformatMessage(String message)
format Message
StringBuilder formattedMsg = new StringBuilder(message);
ArrayList<String> keyWordList = new ArrayList<String>();
keyWordList.add("define");
keyWordList.add("from");
keyWordList.add("select");
keyWordList.add("group");
keyWordList.add("insert");
keyWordList.add(";");
...
StringformatNameToMimeType(final String formatName)
Returns the mime type matching the format name of an image file.
final Iterator<ImageReaderSpi> readers = IIORegistry.lookupProviders(ImageReaderSpi.class);
while (readers.hasNext()) {
    final ImageReaderSpi reader = readers.next();
    final String[] formats = reader.getFormatNames();
    for (String format : formats) {
        if (formatName.equalsIgnoreCase(format)) {
            final String[] mimeTypes = reader.getMIMETypes();
            if (mimeTypes != null && mimeTypes.length > 0) {
...
ListformatParam(String param)
Format query parameter string into list of strings
return Arrays.asList(param.trim().split("\\s+"));
StringformatProtein(String seq)
Format a protein sequence in 6 columns per line, with 10 aa for each column.
StringBuilder sb = new StringBuilder();
int count = 0;
boolean first = true;
List<String> lineList = new ArrayList<>();
for (char c : seq.toCharArray()) {
    if (count % 60 == 0 && !first) {
        lineList.add(sb.toString().trim());
        sb = new StringBuilder();
...
StringformatString(String stringFormat, String... args)
Format string such like "Input params {0} could be {1} "
if (args.length == 0) {
    return stringFormat;
} else {
    List<String> listArgs = new ArrayList<String>();
    for (String arg : args) {
        listArgs.add(arg);
    StringBuilder sb = new StringBuilder(stringFormat);
...