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

24
LINES

< > BotCompany Repo | #1007089 // lastIndexOf - synonym of String.lastIndexOf with handling nulls

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2570L/16K).

static int lastIndexOf(S a, S b) {
  ret a == null || b == null ? -1 : a.lastIndexOf(b);
}

static int lastIndexOf(S a, char b) {
  ret a == null ? -1 : a.lastIndexOf(b);
}

// starts searching from i-1
static <A> int lastIndexOf(L<A> l, int i, A a) {
  if (l == null) ret -1;
  for (i = min(l(l), i)-1; i >= 0; i--)
    if (eq(l.get(i), a))
      ret i;
  ret -1;
}

static <A> int lastIndexOf(L<A> l, A a) {
  if (l == null) ret -1;
  for (int i = l(l)-1; i >= 0; i--)
    if (eq(l.get(i), a))
      ret i;
  ret -1;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 19 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ekrmjmnbrukm, fzcpzdstiiyc, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, ppjhyzlbdabe, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, xrpafgyirdlv

No comments. add comment

Snippet ID: #1007089
Snippet name: lastIndexOf - synonym of String.lastIndexOf with handling nulls
Eternal ID of this version: #1007089/9
Text MD5: 9bb4e442523f131b9315d6929ec7ed24
Transpilation MD5: c99319b77487fdc102916c064d3905b3
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-10-31 12:34:16
Source code size: 543 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 518 / 3482
Version history: 8 change(s)
Referenced in: [show references]