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).

1  
static int lastIndexOf(S a, S b) {
2  
  ret a == null || b == null ? -1 : a.lastIndexOf(b);
3  
}
4  
5  
static int lastIndexOf(S a, char b) {
6  
  ret a == null ? -1 : a.lastIndexOf(b);
7  
}
8  
9  
// starts searching from i-1
10  
static <A> int lastIndexOf(L<A> l, int i, A a) {
11  
  if (l == null) ret -1;
12  
  for (i = min(l(l), i)-1; i >= 0; i--)
13  
    if (eq(l.get(i), a))
14  
      ret i;
15  
  ret -1;
16  
}
17  
18  
static <A> int lastIndexOf(L<A> l, A a) {
19  
  if (l == null) ret -1;
20  
  for (int i = l(l)-1; i >= 0; i--)
21  
    if (eq(l.get(i), a))
22  
      ret i;
23  
  ret -1;
24  
}

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: 591 / 3584
Version history: 8 change(s)
Referenced in: [show references]