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

3
LINES

< > BotCompany Repo | #1029021 // addAndReturnIfNew - add element to a collection and return the element if it was new (null otherwise)

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

Libraryless. Click here for Pure Java version (28L/1K).

static <B, A extends B> A addAndReturnIfNew(Collection<B> c, A a) {
  ret c != null && c.add(a) ? a : null;
}

Author comment

Began life as a copy of #1007299

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: #1029021
Snippet name: addAndReturnIfNew - add element to a collection and return the element if it was new (null otherwise)
Eternal ID of this version: #1029021/2
Text MD5: 50f51ff6e80979f7dae70478ad636552
Transpilation MD5: bf46b83c53e12ffe06d3190e7f34764d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-16 23:50:35
Source code size: 111 bytes / 3 lines
Pitched / IR pitched: No / No
Views / Downloads: 165 / 236
Version history: 1 change(s)
Referenced in: [show references]