de.thksystems.util.lang.StringUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cumin Show documentation
Show all versions of cumin Show documentation
Commons for lang, crypto, xml, dom, text, csv, reflection, annotations, parsing, ...
/*
* tksCommons
*
* Author : Thomas Kuhlmann (ThK-Systems, http://www.thk-systems.de) License : LGPL (https://www.gnu.org/licenses/lgpl.html)
*/
package de.thksystems.util.lang;
public final class StringUtils {
private StringUtils() {
}
/**
* Extract all capitals (uppercase characters) of a string.
*
* - "hello" -> ""
* - "Hello" -> "H"
* - "HelLo" -> "HL"
* - "hello World. Here I am." -> "WHI"
* - null -> null
*
*/
public static String getCapitals(String s) {
if (s == null) {
return null;
}
return s.chars().filter(Character::isUpperCase)
.collect(StringBuilder::new,
StringBuilder::appendCodePoint,
StringBuilder::append)
.toString();
}
}