Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    /**
     * Removes all null, empty and short (<3 char) Strings, trimming elements from the ArrayList
     * @param listOfStrings
     * @return
     */
    public static List<String> filterInvalidCandidates(List<String> listOfStrings) {
        listOfStrings.removeAll(Arrays.asList("", null));
        List<String> validListOfStrings = new ArrayList<>();
        if (listOfStrings.size() > 0) {
            for (String eachString : listOfStrings) {
                if (eachString.length() > 3) {
                    validListOfStrings.add(eachString);
                }
            }
        }
        return validListOfStrings;
    }
}