Assign value of Optional to a variable if present

前端 未结 5 2372
栀梦
栀梦 2021-02-19 02:13

Hi I am using Java Optional. I saw that the Optional has a method ifPresent.

Instead of doing something like:

Optional object = someMeth         


        
5条回答
  •  攒了一身酷
    2021-02-19 02:43

    Optional l = stream.filter..... // java 8 stream condition

            if(l!=null) {
                ObjectType loc = l.get();
                Map.put(loc, null);
            }
    

提交回复
热议问题