当前位置:网站首页>文字组合,不重复,做搜索或查询关键字匹配
文字组合,不重复,做搜索或查询关键字匹配
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
边栏推荐
- Wechat applet positioning and ranging through low-power Bluetooth device (2)
- On September 8, the night before going to Songshan Lake
- Call wechat customer service applet
- 政务云迁移实践 北明数科使用HyperMotion云迁移产品为某政府单位实施上云迁移项目,15天内完成近百套主机迁移
- Switch usage (wechat applet)
- 快速搞懂线程实现的三种方式
- redis数据库讲解(三)redis数据类型
- 使用Postman进行Mock测试
- Postman的安装使用及填坑心得
- GFS分布式文件系统(理论)
猜你喜欢
随机推荐
Chrome插件 之 Selenium IDE、XPath 安装
Can global variables be defined in header files
RecyclerView高级使用(二)-垂直拖拽排序的简单实现
帆软实现一个单选按钮,可以统一设置其他单选按钮的选择状态
mysql 5.1升级到5.611
Easyexcel读取excel表地理位置数据,按中文拼音排序
MySQL数据库讲解(八)
回顾2021:如何帮助客户扫清上云最后一公里的障碍?
正则表达式
DeepinV20安装Mariadb
redis数据库讲解(三)redis数据类型
Kettle -- control parsing
rsync+inotify远程同步
MySQL数据库讲解(十)
预览CSV文件
PyMySQL
使用DialogFragment的一些感受及防踩坑经验(getActivity、getDialog为空,cancelable无效等)
On the multi-level certificate based on OpenSSL, the issuance and management of multi-level Ca, and two-way authentication
POI operation word template replaces data and exports word
HyperBDR云容灾V3.3.0版本发布|容灾功能升级,资源组管理功能优化









