package com.szwl.model.utils.usaEquipment; import org.apache.commons.lang.StringUtils; public class ContainsTest { public static void main(String[] args) { String addr = "日本"; String country = "美国"; String location = "日本,韩国"; ContainsTest containsTest = new ContainsTest(); String s = containsTest.cTest(addr, country, location); System.out.println(s); } public String cTest(String addr, String country, String location) { boolean containsUserInput = true; // location 为空 / 不为空 // country 是中国 / 不是中国 if (StringUtils.isEmpty(location)) { if (country.equals("中国")) { return "国内必须精确到省"; } else { containsUserInput = addr.contains(country); } } else { if (country.equals("中国")) { containsUserInput = addr.contains(location); } else { containsUserInput = addr.contains(country) || addr.contains(location) || location.contains(addr); } } if (!containsUserInput) { // 不包含,返回设备编号 return "{" + 111 + "}"; } return "nih"; } }