首页 > 其他分享 >取list中某一段连续元素

取list中某一段连续元素

时间:2023-06-26 17:35:04浏览次数:297  
标签:endIndex beginIndex int List 元素 list 一段 size

import java.util.List;

public class ListUtils {
    /**
     * 取list中某一段连续元素
     *
     * @param list
     * @param beginIndex
     * @param endIndex
     * @return
     */
    public static <T> List<T> fetchElementFromList(List<T> list, int beginIndex, int endIndex) {
        List<T> result = null;
        if (null != list && !list.isEmpty()) {
            int size = list.size();
            int fromIndex = beginIndex < 0 ? 0 : beginIndex;
            int toIndex = endIndex > size ? size : endIndex;
            if (fromIndex < toIndex) {
                result = list.subList(fromIndex, toIndex);
            }
        }
        return result;
    }
}

 

标签:endIndex,beginIndex,int,List,元素,list,一段,size
From: https://www.cnblogs.com/cool5201314/p/17506258.html

相关文章

  • 34. 在排序数组中查找元素的第一个和最后一个位置
    给你一个按照非递减顺序排列的整数数组nums,和一个目标值target。请你找出给定目标值在数组中的开始位置和结束位置。如果数组中不存在目标值target,返回[-1,-1]。你必须设计并实现时间复杂度为O(logn)的算法解决此问题。示例1:输入:nums=[5,7,7,8,8,10],target=......
  • Arrays.asList()与Collections.unmodifiableList()
    java.util.Arrays#asList返回的是在Arrays实现的ArrayList,privatestaticclassArrayList<E>extendsAbstractList<E>implementsRandomAccess,java.io.Serializable{privatestaticfinallongserialVersionUID=-2764017481108945198L;......
  • IPList.cshtml
    @{ViewData["Title"]="IPList";Layout="~/Views/Shared/_Layout_layui.cshtml";}@sectionCss{}<divclass="demoTablelayui-form"style="padding:10px;background-color:#D4E7F0;">......
  • IPListController
    usingMicrosoft.AspNetCore.Http;usingMicrosoft.AspNetCore.Mvc;usingPT.BLL;usingPT.Common;usingPT.Model;usingPT.Web.Mvc.App_Start;usingSystem;usingSystem.Collections.Generic;usingSystem.Data;usingSystem.Linq;usingSystem.Text;usingSyst......
  • java 8新特性 list转map
    List<Object> 转Map<String,List<String>>Map<String,List<String>>skillAndList=list.stream().collect(Collectors.groupingBy(Employee::getSkillId,Collectors.mapping(Employee::getStudent,Collectors.toList())));List<Obje......
  • Flutter延迟执行一段代码的几种方式以及Timer的说明
    延迟执行在Flutter中,可以使用以下方式实现延迟执行一段代码的效果使用Future.delayed方法:Future.delayed(Duration(milliseconds:500),(){//延迟执行的代码});使用Timer类:Timer(Duration(milliseconds:500),(){//延迟执行的代码});使用Future......
  • 获取年中的天数List 返回
    publicvoiddateList(){//输入年份Console.Write("请输入年份:");intyear=int.Parse(Console.ReadLine());//使用List集合来存储日历varcalendar=GenerateCalendar(year);......
  • 关于Java中ArrayList类的toArray方法详解
    先上源码:publicObject[]toArray(){returnArrays.copyOf(elementData,size);}可以看到ArrayList类的toArray()方法调用了Arrays.copyOf(elementData,size)(其中的elementData是ArrayList类中用来存储对象的数组,size是数组大小),接下来进入其内部:publicsta......
  • iframe标签里的dom元素无法获取
      一、问题类似于这种,想要获取iframe里面的body元素获取不到;  二、原因看了一下帖子,是由作用域的问题,我们的querySelector只能获取到本作用域下的dom元素。 三、解决constbar=document.getElementById('ueditor_0').contentDocument.querySelectorAll('body')......
  • C++面试八股文:std::vector和std::list,如何选择?
    某日二师兄参加XXX科技公司的C++工程师开发岗位第24面:面试官:list用过吗?二师兄:嗯,用过。面试官:请讲一下list的实现原理。二师兄:std::list被称为双向链表,和C中手写双向链表本质上没有大的区别。list对象中有两个指针,一个指向上一个节点(node),一个指向下一个节点(node)。二师兄:与手写......