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

8
LINES

< > BotCompany Repo | #1027916 // takeFirstFromMap

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

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

1  
static <A, B> Map<A, B> takeFirstFromMap(int n, Map<A, B> map) {
2  
  if (map == null) null;
3  
  Map<A, B> map2 = similarEmptyMap(map);
4  
  if (n > 0)
5  
    for (Map.Entry<A, B> e : map.entrySet())
6  
      if (n-- <= 0) break; else map2.put(e.getKey(), e.getValue());
7  
  ret map2;
8  
}

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: #1027916
Snippet name: takeFirstFromMap
Eternal ID of this version: #1027916/3
Text MD5: c5f73c6e78c1e4783b24d79b0dde829d
Transpilation MD5: 2e320408d7c72f79d8272ddf4cf78263
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-04-17 11:37:45
Source code size: 277 bytes / 8 lines
Pitched / IR pitched: No / No
Views / Downloads: 234 / 325
Version history: 2 change(s)
Referenced in: [show references]