Java tutorial
//package com.java2s; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; public class Main { public static String generateTql(List<String> fields, String api, Map<String, String> params) { params.put("is_mobile", "true"); String tql = "select "; for (int i = 0; i < fields.size(); i++) { if (i == fields.size() - 1) { tql += fields.get(i); } else { tql += fields.get(i); tql += ","; } } tql += " from " + api; tql += " where "; Set<Entry<String, String>> entrySet = params.entrySet(); int size = entrySet.size(); for (Entry<String, String> entry : entrySet) { tql += entry.getKey() + " = " + entry.getValue(); size--; if (size <= 0) { } else { tql += " and "; } } return tql; } }