首页 > 其他 > 详细

String 去重,区分大小写

时间:2016-08-21 16:42:04      阅读:149      评论:0      收藏:0      [点我收藏+]

题目要求:去除,和.,相同的单词去除后面的。不区分大小写

示例:输入:There is a will,there is a way. 输出There is a will there way

 

答案代码:

 String s = "There is a will there is a way";
Pattern p = Pattern.compile("[,.]");
String ss = p.matcher(s).replaceAll("");
LinkedHashSet<String> set = new LinkedHashSet<String>(Arrays.asList(ss.split("[技术分享\\s*\t\r\n]")));
set.forEach(System.out::println); 
 
备注:
1主要用到一种数据结构LinkedHashSet,达到去重不影响顺序,区分大小写的目的。
2用正则匹配,去掉,和.

String 去重,区分大小写

原文:http://www.cnblogs.com/MiWang/p/5792856.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!