All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.tron.p2p.utils.CollectionUtils Maven / Gradle / Ivy

The newest version!
package org.tron.p2p.utils;

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


public class CollectionUtils {

  public static  List truncate(List items, int limit) {
    if (limit > items.size()) {
      return new ArrayList<>(items);
    }
    List truncated = new ArrayList<>(limit);
    for (T item : items) {
      truncated.add(item);
      if (truncated.size() == limit) {
        break;
      }
    }
    return truncated;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy