java Map集合模糊匹配

public class StringTest {
    public static void main(String[] args) {
        Map<String, Object>map=new ConcurrentHashMap<String, Object>();
       map.put("safein", "safein");
       map.put("safein1tebg23", "safein23");
       map.put("twjsafein123", "twjsafein1233");
       map.put("twj", "twj");
       List<?> list=getLikeByMap(map,"twj");
    for (Object val : list) {
        System.err.println(val.toString());
    }
    }
    public static List<String> getLikeByMap(Map<String, Object>map,String keyLike){
        List<String> list=new Vector<>();        
        for (Map.Entry<String, Object> entity : map.entrySet()) {
                            if(entity.getKey().indexOf(keyLike)>-1){
                                    list.add((String) entity.getValue());
                            }

                    }    

        return list;
    }
}
    原文作者:twjitm
    原文地址: https://blog.csdn.net/baidu_23086307/article/details/52943226
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞