Java集合综合练习2——指定文本中查找单词

本文介绍如何在Java中使用集合(如TreeMap和TreeSet)实现字符串中按字母或单词的查找和模糊查找功能。重点在于利用TreeMap的自动排序和去重特性,以及Collection接收Map值的方法。

给定的字符串中根据输入字母或单词进行查找或模糊查找

用到集合技术:
TreeMap 集合嵌套
TreeSet 优点:针对于这个问题来讲 自动排序,且不会出现重复元素
Collection 集合接收对应Map的值

具体代码如下

public static void main(String[] args) {
   
   
		
		String source = "We've all met the type of individual who simply must take charge. Whether it's a" + 
				"decision-making session, a basketball game, or a family outing, they can't help grabbing the lead" + 
				"dog position and clinging on to it for dear life. They believe they're natural born leaders.";
		
		//1 清理原始字符串的标点符号
		source = source.toString().replaceAll(",","")
				.replaceAll("'s", "")
				.replaceAll("'t", "")
				.replaceAll("'", "")
				.replaceAll("\\.", "")
				.toLowerCase();
		
		//将整理好的单词放入数组中去
		String []wordArray = source.split(" ");
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值