Java Utililty Methods List Trim

List of utility methods to do List Trim

Description

The list of methods to do List Trim are organized into topic(s).

Method

StringtoStringList(List list, String delimiter, boolean isTrim, boolean isRemoveEmpty)
Converts a List of object to a string list separated by specified delimiter.
(Do trim for each string element if isTrim is true).
StringBuffer sb = new StringBuffer();
boolean firstElem = true;
for (Object o : list) {
    String s = (o == null) ? "" : o.toString();
    if (isTrim) {
        s = s.trim();
    if (isRemoveEmpty && s.equals("")) {
...
Listtrim(final List row)
Trim all values in row.
final List<String> formattedRow = new ArrayList<>();
final Iterator<String> it = row.iterator();
while (it.hasNext()) {
    formattedRow.add(it.next().trim());
return formattedRow;
voidtrim(List data, boolean removeEmptyLines)
trim
for (int i = 0; i < data.size(); i++) {
    final String s = data.get(i);
    data.set(i, s.trim());
if (removeEmptyLines) {
    for (final Iterator<String> it = data.iterator(); it.hasNext();) {
        if (it.next().length() == 0) {
            it.remove();
...
voidtrim(List strs)
Trims every string of a collection.
for (int i = 0, n = strs.size(); i < n; i++)
    strs.set(i, strs.get(i).trim());
ListtrimElements(List list)
trim Elements
for (int i = 0; i < list.size(); i++) {
    list.set(i, list.get(i).trim());
return removeEmptyStrings(list);
ListtrimEndDigital(List strs)
trim End Digital
String endStr = strs.get(strs.size() - 1);
try {
    Integer.parseInt(endStr);
    strs.remove(strs.size() - 1);
} catch (NumberFormatException e) {
    return strs;
return strs;
...
StringtrimIfLastIndex(List suggestedList, String suggestedWords, int i)
trim If Last Index
if (isLastIndex(suggestedList, i)) {
    suggestedWords = trimSuggestions(suggestedWords);
return suggestedWords;
StringtrimKeyFormat(String s3KeyFormat, List disallowedKeys)
trim Key Format
int lowestIndex = s3KeyFormat.length();
for (String disallowedKey : disallowedKeys) {
    int index = s3KeyFormat.indexOf(disallowedKey);
    if (index != -1 && index < lowestIndex) {
        lowestIndex = index;
if (lowestIndex == -1) {
...
ListtrimLeadingWhitespaces(List lines)
Trims leading whitespaces.
if (lines.isEmpty()) {
    return lines;
String lead = null;
for (int i = 0, n = lines.size(); i < n; i++) {
    String line = lines.get(i);
    if (line.isEmpty() == false) {
        if (lead == null) {
...
ListtrimList(List list)
trim List
if (list != null) {
    for (int i = 0; i < list.size(); i++) {
        String val = list.get(i);
        list.set(i, trimStr(val));
return list;