Java Utililty Methods List Truncate

List of utility methods to do List Truncate

Description

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

Method

ListtruncateList(List list, int len)
Returns a truncated version of the specified List.
if (len >= list.size())
    return list;
ArrayList<T> newList = new ArrayList<T>(len);
for (int ii = 0; ii < len; ii++) {
    newList.add(list.get(ii));
return newList;
ListtruncateStringList(List strings, String truncateFrom)
Removes all entries in the list after truncateFrom string (inclusive truncateFrom entry)
if (strings == null)
    return null;
int index = strings.indexOf(truncateFrom);
if (index >= 0)
    return strings.subList(0, index);
return strings;
ListtruncateVersionFromModFileName(List fileNames)
truncate Version From Mod File Name
String pattern = "([a-zA-Z0-9\\s-]+)([-_\\s\\[])(.+)(.jar)";
List<String> truncatedNames = new ArrayList<>();
for (String fileName : fileNames) {
    String newName = fileName.replaceAll(pattern, "$1");
    truncatedNames.add(newName.trim());
return truncatedNames;