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

1  
static O[] toArray(Collection c) {
2  
  ret toObjectArray(c);
3  
}
4  
5  
static <A> A[] nuLike toArray(Class<A> type, Iterable<A> c) {
6  
  ret toArray(c, type);
7  
}
8  
9  
static <A> A[] toArray(Class<A> type, Cl<A> c) {
10  
  ret toArray(c, type);
11  
}
12  
13  
static <A> A[] toArray(Cl<A> c, Class<A> type) {
14  
  A[] a = arrayOfType(l(c), type);
15  
  if (a.length == 0) ret a;
16  
  asList(c).toArray(a);
17  
  ret a;
18  
}
19  
20  
static <A> A[] toArray(Iterable<A> c, Class<A> type) {
21  
  var c2 = asList(c);
22  
  A[] a = arrayOfType(l(c2), type);
23  
  if (a.length == 0) ret a;
24  
  c2.toArray(a);
25  
  ret a;
26  
}
27  
28  
// array must have correct length and will be filled
29  
static <A> A[] toArray(A[] array, Collection c) {
30  
  if (array == null || c == null) null;
31  
  asList(c).toArray(array);
32  
  ret array;
33  
}

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: 513 / 659
Version history: 11 change(s)
Referenced in: [show references]