It seems that you want to find a card key based on a specific pattern. This can be done by iterating over all the keys:
private static String PREFIX = "<job_id>"; private static String SUFFIX = "</job_id>"; public static String extractJobId(Map<String, ?> map) { for(String key : map.keySet()) { if(key.startsWith(PREFIX) && key.endsWith(SUFFIX)) return key.substring(PREFIX.length(), key.length()-SUFFIX.length()); }
If you can have multiple job_id keys and want to check if they are all the same, you can create an intermediate set instead:
public static Set<String> extractJobIds(Map<String, ?> map) { Set<String> result = new HashSet<>(); for(String key : map.keySet()) { if(key.startsWith(PREFIX) && key.endsWith(SUFFIX)) result.add(key.substring(PREFIX.length(), key.length()-SUFFIX.length())); } return result; }
Now you can use this method to compare job_id of different cards:
if(Objects.equals(extractJobIds(xmlFileMap), extractJobIds(compareMap))) {
source share