This is what validator suggests to check. But as i can see they are present. Any idea guys?
package com.codegym.task.task22.task2208;
import java.util.Map;
import java.util.HashMap;
import java.util.Formatter;
/*
Build a WHERE query
*/
public class Solution {
public static void main(String[] args) {
Map<String, String> map = new HashMap<>();
map.put("name", "Johnson");
map.put("country", "United States");
map.put("citY", "Los Angeles");
map.put("age", null);
System.out.println(getQuery(map));
}
public static String getQuery(Map<String, String> params) {
String[] arr = {"name", "country", "city", "age"};
StringBuilder sb = new StringBuilder();
Formatter fm = new Formatter(sb);
for (int i = 0; i < arr.length; i++) {
for(Map.Entry<String, String> me : params.entrySet()){
if (me.getKey().equalsIgnoreCase(arr[i])&& me.getValue()!=null)
fm.format("%s = '%s' and ",arr[i], me.getValue());
}
}
sb.delete(sb.length()-5, sb.length());
return sb.toString();
}
}