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

7
LINES

< > BotCompany Repo | #1024478 // mapPutOrCreate - make HashMap if null

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

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

static <A, B> Map<A, B> mapPutOrCreate(Map<A, B> map, A key, B value) {
  if (key != null && value != null) {
    if (map == null) map = new HashMap;
    map.put(key, value);
  }
  ret map;
}

Author comment

Began life as a copy of #1024463

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1024478
Snippet name: mapPutOrCreate - make HashMap if null
Eternal ID of this version: #1024478/1
Text MD5: 402c4ea235170679685bf24f900f11d4
Transpilation MD5: bb90b4ee347a7fb8df4975e984546a66
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-13 18:48:55
Source code size: 197 bytes / 7 lines
Pitched / IR pitched: No / No
Views / Downloads: 282 / 412
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1024510 - mapPutOrCreate_multi
#1026134 - orderedMapPutOrCreate - make LinkedHashMap if null
#1030902 - putOrCreate - make HashMap if null. allow null keys and values