Java List Truncate truncateList(final List full, int maxSize)

Here you can find the source of truncateList(final List full, int maxSize)

Description

Truncates the given list to have the given maximum size.

License

Apache License

Parameter

Parameter Description
full the full ist to truncate
maxSize the maximum size of the returned view

Return

a view of the full list as with .

Declaration

public static <E> List<E> truncateList(final List<E> full, int maxSize) 

Method Source Code


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

import java.util.*;

public class Main {
    /**/*w  ww  .j a  va2  s .  c o m*/
     * Truncates the given list to have the given maximum size.
     * @param full the full ist to truncate
     * @param maxSize the maximum size of the returned view
     * @return a view of the full list as with {@link List#subList(int, int)}.
     */
    public static <E> List<E> truncateList(final List<E> full, int maxSize) {
        final int numToDisplay = Math.min(full.size(), maxSize);
        return full.subList(0, numToDisplay);
    }
}

Related

  1. trunc(List as, int length)
  2. truncate(final List list, final int newSize)
  3. truncate(final List items, final int limit)
  4. truncate(List list, int length)
  5. truncateEnd(List list, int numElements)
  6. truncateList(int offset, int count, List originalList)
  7. truncateList(List input, int maxSize)
  8. truncateList(List list, int len)
  9. truncateStringList(List strings, String truncateFrom)