Java Utililty Methods String Whitespace Delete

List of utility methods to do String Whitespace Delete

Description

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

Method

StringdeleteWhitespace(CharSequence sequence)
delete Whitespace
if (!hasLength(sequence)) {
    return EMPTY;
StringBuilder sb = new StringBuilder(sequence.length());
for (int i = 0; i < sequence.length(); i++) {
    char currentChar = sequence.charAt(i);
    if (!Character.isWhitespace(currentChar)) {
        sb.append(currentChar);
...
StringdeleteWhitespace(CharSequence str)
delete Whitespace
StringBuilder sb = new StringBuilder(str.length());
for (int i = 0; i < str.length(); i++) {
    char c = str.charAt(i);
    if (i > 0 && Character.isWhitespace(c) && Character.isWhitespace(str.charAt(i - 1)))
        continue;
    if (c == '\r' || c == '\n') {
        sb.append(' ');
        continue;
...
StringdeleteWhitespace(final String s)

Deletes all whitespaces from a String as defined by Character#isWhitespace(char) .

if (isEmpty(s)) {
    return s;
final int sz = s.length();
final char[] chs = new char[sz];
int count = 0;
for (int i = 0; i < sz; i++) {
    if (!Character.isWhitespace(s.charAt(i))) {
...
StringdeleteWhitespace(final String str)
delete Whitespace
if (str == null || str.isEmpty()) {
    return str;
final int sz = str.length();
final char[] chs = new char[sz];
int count = 0;
for (int i = 0; i < sz; i++) {
    if (!Character.isWhitespace(str.charAt(i))) {
...
StringdeleteWhitespace(String s)
delete Whitespace
final String result;
if (s == null) {
    result = null;
} else {
    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
        final char c = s.charAt(i);
        if (!Character.isWhitespace(c)) {
...
StringdeleteWhiteSpace(String s)
delete White Space
StringBuilder r = new StringBuilder();
if (s != null) {
    for (int i = 0; i < s.length(); i++) {
        if (!Character.isWhitespace(s.codePointAt(i))) {
            r.append(s.charAt(i));
return r.toString();
StringdeleteWhitespace(String str)
delete Whitespace
if (str == null) {
    return null;
int sz = str.length();
StringBuffer buffer = new StringBuffer(sz);
for (int i = 0; i < sz; i++) {
    if (!Character.isWhitespace(str.charAt(i))) {
        buffer.append(str.charAt(i));
...
StringdeleteWhitespace(String str)

Deletes all whitespaces from a String as defined by Character#isWhitespace(char) .

if (isBlank(str)) {
    return str;
int sz = str.length();
char[] chs = new char[sz];
int count = 0;
for (int i = 0; i < sz; i++) {
    if (!Character.isWhitespace(str.charAt(i))) {
...
StringdeleteWhitespace(String str)
delete Whitespace
if (isEmpty(str)) {
    return str;
int sz = str.length();
char[] chs = new char[sz];
int count = 0;
for (int i = 0; i < sz; i++) {
    if (!Character.isWhitespace(str.charAt(i))) {
...
StringdeleteWhitespace(String str)

Deletes all whitespaces from a String as defined by Character#isWhitespace(char) .

 StringUtils.deleteWhitespace(null)         = null StringUtils.deleteWhitespace("")           = "" StringUtils.deleteWhitespace("abc")        = "abc" StringUtils.deleteWhitespace("   ab  c  ") = "abc" 
if (isEmpty(str)) {
    return str;
int sz = str.length();
char[] chs = new char[sz];
int count = 0;
for (int i = 0; i < sz; i++) {
    if (!Character.isWhitespace(str.charAt(i))) {
...