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

com.github.bingoohuang.utils.lang.Listx Maven / Gradle / Ivy

package com.github.bingoohuang.utils.lang;

import com.google.common.collect.Lists;

import java.util.List;

import static com.google.common.collect.Sets.newHashSet;

public class Listx {
    public static  List head(List list, int len) {
        return list.size() <= len ? list : list.subList(0, len);
    }

    public static  T head(List list) {
        return list.isEmpty() ? null : list.get(0);
    }

    public static  T last(List list) {
        return list.isEmpty() ? null : list.get(list.size() - 1);
    }

    public static  List tail(List list) {
        return list.size() > 1 ? list.subList(1, list.size() - 1) : Lists.newArrayList();
    }

    public static  List unique(List original) {
        return com.google.common.collect.Lists.newArrayList(newHashSet(original));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy