Java tutorial
//package com.java2s; import java.util.Arrays; import java.util.List; import java.util.Locale; public class Main { private static List<String> KEYWORDS = Arrays.asList("OR", "AND"); public static String toMatchString(List<String> terms) { StringBuilder builder = new StringBuilder(); for (String term : terms) { if (builder.length() != 0) { builder.append(' '); } if (isKeyword(term)) { builder.append(term.toUpperCase(Locale.ENGLISH)); } else if (term.contains("*") || term.startsWith("-")) { builder.append(term); } else { builder.append('*').append(term).append('*'); } } return builder.toString(); } static boolean isKeyword(String term) { return KEYWORDS.contains(term.toUpperCase(Locale.ENGLISH)); } }