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


< > BotCompany Repo | #1000719 // dropLast function (drop last elements of array/list/string)

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

Libraryless. Click here for Pure Java version (2455L/15K).

static <A> A[] dropLast(A[] a, int n default 1) {
  if (a == null) null;
  n = Math.min(n, a.length);
  A[] b = arrayOfSameType(a, a.length-n);
  System.arraycopy(a, 0, b, 0, b.length);
  ret b;

static <A> L<A> dropLast(L<A> l) {
  ret subList(l, 0, l(l)-1);

static <A> L<A> dropLast(int n, L<A> l) {
  ret subList(l, 0, l(l)-n);

static <A> L<A> dropLast(Iterable<A> l) {
  ret dropLast(asList(l));

static S dropLast(S s) {
  ret substring(s, 0, l(s)-1);

static S dropLast(S s, int n) {
  ret substring(s, 0, l(s)-n);

static S dropLast(int n, S s) {
  ret dropLast(s, n);

Author comment

Began life as a copy of #1000705

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ekrmjmnbrukm, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1000719
Snippet name: dropLast function (drop last elements of array/list/string)
Eternal ID of this version: #1000719/9
Text MD5: 7f4ea095e27006e7f7958a71d05215f7
Transpilation MD5: cb25bbeb95b8b3dc94f5e451c6906f56
Author: stefan
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-11 18:49:57
Source code size: 623 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 592 / 1213
Version history: 8 change(s)
Referenced in: [show references]