Map集合模糊匹配

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());
  }
}

/**
* map :Map
* key:需要匹配的key  
*/
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;
}

 

posted @ 2022-03-09 14:28  丶Ronnie  阅读(1435)  评论(0)    收藏  举报