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

15
LINES

< > BotCompany Repo | #1029349 // reversedSubstring

JavaX fragment (include)

1  
sS reversedSubstring(S s, int x, int y) {
2  
  if (s == null) null;
3  
  if (x < 0) x = 0;
4  
  int n = s.length();
5  
  if (y < x) y = x;
6  
  if (y > n) y = n;
7  
  if (x >= y) ret "";
8  
  
9  
  // TODO: Is this actually faster than reversed(substring(...))?
10  
  char[] chars = new[y-x];
11  
  int j = y-x;
12  
  for (int i = x; i < y; i++)
13  
    chars[--j] = s.charAt(i);
14  
  ret String.valueOf(chars);
15  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1029349
Snippet name: reversedSubstring
Eternal ID of this version: #1029349/3
Text MD5: 59d8b09190fb3bd0b6dcfc8d34173d42
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-08-01 22:41:56
Source code size: 384 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 211 / 238
Version history: 2 change(s)
Referenced in: [show references]