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

7
LINES

< > BotCompany Repo | #1010783 // collectionGet - get element at index from collection

JavaX fragment (include)

static <A> A collectionGet(Collection<A> c, int idx) {
  if (c == null || idx < 0 || idx >= l(c)) null;
  if (c instanceof L) ret listGet((L<A>) c, idx);
  Iterator<A> it = c.iterator();
  for (int i = 0; i < idx; i++) if (it.hasNext()) it.next(); else null;
  ret it.hasNext() ? it.next() : null;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1010783
Snippet name: collectionGet - get element at index from collection
Eternal ID of this version: #1010783/5
Text MD5: bd5d08e93d6cab252370dd457657dbee
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-12-03 13:55:09
Source code size: 305 bytes / 7 lines
Pitched / IR pitched: No / No
Views / Downloads: 562 / 617
Version history: 4 change(s)
Referenced in: [show references]