当前位置:网站首页>文字组合,不重复,做搜索或查询关键字匹配
文字组合,不重复,做搜索或查询关键字匹配
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
边栏推荐
- Logging module
- RobotFramework 之 项目框架
- Wechat applet obtains login user information, openid and access_ token
- sql中出现一个变态问题
- 政务云迁移实践 北明数科使用HyperMotion云迁移产品为某政府单位实施上云迁移项目,15天内完成近百套主机迁移
- 帆软分割求解:一段字符串,只取其中某个字符(所需要的字段)
- 云迁移的六大场景
- 第四届“传智杯”全国大学生IT技能大赛(决赛B组) 题解
- 使用DialogFragment的一些感受及防踩坑经验(getActivity、getDialog为空,cancelable无效等)
- 倒计时1天~2022云容灾产品线上发布会即将开始
猜你喜欢
随机推荐
基於CM管理的CDH集群集成Phoenix
Indoor and outdoor map switching (indoor three-point positioning based on ibeacons)
Call wechat customer service applet
Nifi 快速安装及文件同步操作
OpenStack命令操作
squid代理
MYSQL 主从同步避坑版教程
RobotFramework 之 文件上传和下载
redis数据库讲解(四)主从复制、哨兵、Cluster群集
Redis数据库讲解(一)
Oracle-数据泵使用
JSP学习2
VMware Workstation 无法连接到虚拟机。系统找不到指定的文件
JDBC详解
mysql 5.1升级到5.610
Win10 comes with groove music, which can't play cue and ape files. It's a curvilinear way to save the country. It creates its own aimpack plug-in package, and aimp installs DSP plug-in
修改ddt生成的测试用例名称
findstr不是内部或外部命令解决方法
帆软中单元格中隔行变色以及数量大于100字体变大变红设置
Subscription number development of wechat applet (message push)