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

33
LINES

< > BotCompany Repo | #1014327 // toArray - synonym of toObjectArray; also allows a type

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

Libraryless. Click here for Pure Java version (5283L/29K).

static O[] toArray(Collection c) {
  ret toObjectArray(c);
}

static <A> A[] nuLike toArray(Class<A> type, Iterable<A> c) {
  ret toArray(c, type);
}

static <A> A[] toArray(Class<A> type, Cl<A> c) {
  ret toArray(c, type);
}

static <A> A[] toArray(Cl<A> c, Class<A> type) {
  A[] a = arrayOfType(l(c), type);
  if (a.length == 0) ret a;
  asList(c).toArray(a);
  ret a;
}

static <A> A[] toArray(Iterable<A> c, Class<A> type) {
  var c2 = asList(c);
  A[] a = arrayOfType(l(c2), type);
  if (a.length == 0) ret a;
  c2.toArray(a);
  ret a;
}

// array must have correct length and will be filled
static <A> A[] toArray(A[] array, Collection c) {
  if (array == null || c == null) null;
  asList(c).toArray(array);
  ret array;
}

Author comment

Began life as a copy of #1002013

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1014327
Snippet name: toArray - synonym of toObjectArray; also allows a type
Eternal ID of this version: #1014327/12
Text MD5: 40293c904fc4e7f5ef8abd21a9acda77
Transpilation MD5: 4783d508afcc4ecfb9156ce746d72fee
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-12 22:04:25
Source code size: 762 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 420 / 540
Version history: 11 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1034771 - toArrayOrNull