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

15
LINES

< > BotCompany Repo | #1029349 // reversedSubstring

JavaX fragment (include)

sS reversedSubstring(S s, int x, int y) {
  if (s == null) null;
  if (x < 0) x = 0;
  int n = s.length();
  if (y < x) y = x;
  if (y > n) y = n;
  if (x >= y) ret "";
  
  // TODO: Is this actually faster than reversed(substring(...))?
  char[] chars = new[y-x];
  int j = y-x;
  for (int i = x; i < y; i++)
    chars[--j] = s.charAt(i);
  ret String.valueOf(chars);
}

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: 138 / 165
Version history: 2 change(s)
Referenced in: [show references]