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

示例:输入: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 去重,区分大小写的更多相关文章

  1. list去重,String[]去重,String[]去空,StringBuffer去重,并且以','隔开,list拆分

    1.// 删除ArrayList中重复元素 public static void removeDuplicate(List list) { HashSet h = new HashSet(list); ...

  2. String去重方法

    思路:利用集合的contains方法将某个字符串中的集合中没有的单个字符添加到集合中,然后再将集合中每个元素做拼接 @Test public void aa5(){ String aa="a ...

  3. 【java基础学习一】int[]、Integer[]、String[] 排序( 正序、倒叙)、去重

    调用: //重复项有9.5.1.2 int[] ints = new int[]{9,4,7,8,2,5,1,6,2,5,9,1}; arrayIntTest(ints); ///////////// ...

  4. LINQ to SQL语句(15)之String

    LINQ to SQL支持以下String方法.但是不同的是默认情况下System.String方法区分大小写.而SQL则不区分大小写. 1.字符串串联(String Concatenation) v ...

  5. Java String字符串方法

    1.String构造函数 1> String() 2> String(char[] chars) String(char[] chars,int startIndex,int numCha ...

  6. java11-6 String类的其它功能

    String类的其他功能: 替换功能: String replace(char old,char new) String replace(String old,String new) 去除字符串两空格 ...

  7. js 数组排除重复值(string)

    前提:数组中的元素类型为:string 在网上看了许多高大尚的文章,还是解决不了我的string arry 的问题,只能怪自己脑残了,上代码: <!DOCTYPE html> <ht ...

  8. String类中常用的方法(重要)

    1.字符串与字节 public String(byte[] byte); 将全部字节变成字符串 public String (byte[] byte,int offset,int length) 将部 ...

  9. java String的各种方法及操作

    No. 方法名称 功能 字符与字符串 01 public String(char[] value) 将字符数组中所有内容变为字符串 02 public String(char[] value,int ...

随机推荐

  1. Asp.Net MVC 路由 - Asp.Net 编程 - 张子阳

    http://cache.baiducontent.com/c?m=9d78d513d98316fa03acd2294d01d6165909c7256b96c4523f8a9c12d522195646 ...

  2. 【linux】rpm常见命令

    查看包依赖模块:http://www.rpmfind.net/ rpm  -ivh [包名] :安装rpm包 rpm  -e [包名] :删除rpm包 rpm  -aq [包名] :查询rpm包 rp ...

  3. AppCan做的图片上传代码

    存在AppCan里的网页 index.html <!DOCTYPE html> <html class="um landscape min-width-240px min- ...

  4. DateGridView中添加下拉框列并实现数据绑定、更改背景色

    1.添加下拉框 代码实现==> using System; using System.Collections.Generic; using System.Windows.Forms; names ...

  5. golang的的模板引擎之pongo2

    https://github.com/flosch/pongo2 beego的扩展包 https://github.com/yansuan/beego-pongo2 gin的扩展包 https://g ...

  6. VB脚本调用exe应用程序并传递参数

    VB脚本调用应用程序,并传递参数给exe应用程序: Private Sub CommandButton1_Click() Dim a a = Shell("D:\\ExperimentLin ...

  7. web开发

    教程 html教程 CSS 教程 JavaScript 教程 参考手册 HTML 4.01 / XHTML 1.0 参考手册 CSS 参考手册 JavaScript 参考手册 PHP 手册 CodeI ...

  8. 多线程同步 wait notify

    package test; public class Test implements Runnable{ public static int j =0; @Override public void r ...

  9. svn 中 版本回退

    譬如有个文件,有十个版本,假定版本号是1,2,3,4,5,6,7,8,9,10. Revert to this revision: 如果在版本6这里点击“Revert to this revision ...

  10. NodeJS 学习资料

    1. npm 除Node本身提供的API外,现在有不少第三方模块可极大的提高开发效率,npm就是Node的软件包管理器,可以用它安装所需软件包并发布自己为nodejs写的软件包. npm安装node扩 ...