当前位置:网站首页>文字组合,不重复,做搜索或查询关键字匹配
文字组合,不重复,做搜索或查询关键字匹配
2022-04-23 14:08:00 【阿闰】
public static Boolean check(List<String> list, String city) {
for (String s : list) {
if (s.equals(city)) {
return true;
}
}
return false;
}
public static void main(String[] args) {
List<String> city = new ArrayList<String>();//1,3,7,13
city.add("上海");
city.add("北京");
city.add("深圳");
city.add("南京");
List<String> tempList = new ArrayList<String>();
for (String c : city) {
StringBuffer str = new StringBuffer();
str.append(c);
if (!tempList.contains(c)) {
tempList.add(c);
}
StringBuffer str2 = new StringBuffer();
for (String s : city) {
if (str2.length() > 0) {
str2.append(",").append(s);
} else {
str2.append(s);
}
String[] split2 = str2.toString().split(",");
Arrays.sort(split2);
String data2 = String.join(",", split2);
if (!tempList.contains(data2) && !check(tempList, data2)) {
tempList.add(data2);
} else {
str2 = new StringBuffer();
}
if (!c.equals(s)) {
if (str.length() > 0) {
str.append(",").append(s);
} else {
str.append(s);
}
String[] split = str.toString().split(",");
Arrays.sort(split);
String data = String.join(",", split);
if (!tempList.contains(data) && !check(tempList, data)) {
tempList.add(data);
}
}
}
String[] split = str.toString().split(",");
Arrays.sort(split);
String data = String.join(",", split);
if (!tempList.contains(data) && !check(tempList, data)) {
tempList.add(data);
}
}
tempList.forEach(e -> {
System.out.println(e);
});
}
上海
北京
上海,北京
北京,深圳
上海,北京,深圳
北京,南京,深圳
上海,北京,南京,深圳
深圳
南京,深圳
上海,深圳
南京
上海,南京
上海,北京,南京
版权声明
本文为[阿闰]所创,转载请带上原文链接,感谢
https://blog.csdn.net/wasd986523/article/details/121851814
边栏推荐
猜你喜欢

HyperMotion云迁移完成阿里云专有云产品生态集成认证

基于CM管理的CDH集群集成Phoenix

DDT+Excel进行接口测试

连接公司跳板机取别名

Operation instructions of star boundary automatic text translator (advanced version)

VMware 15pro mounts the hard disk of the real computer in the deepin system

Recyclerview advanced use (I) - simple implementation of sideslip deletion

Intégration de Clusters CDH Phoenix basée sur la gestion cm

squid代理

帆软之单元格部分字体变颜色
随机推荐
关于Jmeter启动闪退问题
帆软实现一个单选按钮,可以统一设置其他单选按钮的选择状态
Easyexcel读取excel表地理位置数据,按中文拼音排序
Understand the concepts of virtual base class, virtual function and pure virtual function (turn)
Multiple inheritance virtual base exercises
Jmeter设置环境变量支持在任意终端目录输入jmeter直接启动
VMWare安装64位XP中文教程
Mock测试
On September 8, the night before going to Songshan Lake
About the configuration and use of json5 in nodejs
不同时间类型的执行计划计算
org.apache.parquet.schema.InvalidSchemaException: A group type can not be empty. Parquet does not su
mysql 5.1升级到5.69
How QT designer adds resource files
帆软实现分页时第一行和最后两行冻结方式
容灾有疑问?点这里
多云数据流转?云上容灾?年前最后的价值内容分享
关于云容灾,你需要知道这些
Essential difference between restful WebService and gSOAP webservice
快速搞懂线程实现的三种方式