Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data


< > BotCompany Repo | #1002310 - subList function - safer version of List.subList

JavaX fragment (include)

static <A> L<A> subList(L<A> l, int startIndex) {
  ret subList(l, startIndex, l(l));

static <A> L<A> subList(int startIndex, int endIndex, L<A> l) {
  ret subList(l, startIndex, endIndex);

static <A> L<A> subList(L<A> l, int startIndex, int endIndex) {
  if (l == null) null;
  int n = l(l);
  startIndex = Math.max(0, startIndex);
  endIndex = Math.min(n, endIndex);
  if (startIndex >= endIndex) ret ll();
  if (startIndex == 0 && endIndex == n) ret l;
  ret l.subList(startIndex, endIndex);

ifclass IntRange
static <A> L<A> subList(L<A> l, IntRange r) {
  ret subList(l, r.start, r.end);

Author comment

Began life as a copy of #1001911

download  show line numbers  debug dex   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, podlckwnjdmb, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, xrpafgyirdlv

No comments. add comment

Snippet ID: #1002310
Snippet name: subList function - safer version of List.subList
Eternal ID of this version: #1002310/6
Text MD5: 088f2703d64d4e7ed818ce8bd736cc17
Author: stefan
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-25 21:35:10
Source code size: 630 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 510 / 3659
Version history: 5 change(s)
Referenced in: [show references]

Formerly at &