I surely miss something but when I test it out with a map I create it seems to work correctly.
Any ideas?
package com.codegym.task.task22.task2208;
import java.util.Formatter;
import java.util.HashMap;
import java.util.Map;
/*
Build a WHERE query
*/
public class Solution {
public static void main(String[] args) {
}
public static String getQuery(Map<String, String> params) {
Map<String, String> map = new HashMap<>(params);
StringBuilder sb = new StringBuilder();
Formatter fmt = new Formatter(sb);
for (Map.Entry<String, String> entry : map.entrySet()) {
if (entry.getValue() != null) {
fmt.format("%s = '%s' and ", entry.getKey(), entry.getValue());
}
}
sb.delete(sb.length()-4, sb.length());
return sb.toString().trim();
}
}