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

示例:输入: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. 使用UpdatePanel 页面脚本不起作用

    在后台中这样注册js方法 ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "", " ...

  2. WPF 数据绑定

    1.1绑定到对象 1.1.1.前台绑定 前台代码 5: </Grid> 1: <Grid x:Name=”GridProductDetails”> 2:   3: <Te ...

  3. LintCode "Previous Permutation"

    A reverse version of the Dictionary algorithm :) If you AC-ed "Next Permutation II", copy ...

  4. 建立一个node.js服务器(使用express搭建第一个Web环境)

    一.官网下载node.js 下载地址:https://nodejs.org/en/download/ 根据向导,下一步安装就可以了! 二.使用express搭建Web环境 express是一个开源的n ...

  5. 【maven】解决Missing artifact jdk.tools:jdk.tools:jar:1.6

    解决在pom.xml文件中出现的Missing artifact jdk.tools:jdk.tools:jar:1.6问题, <dependency> <groupId>jd ...

  6. Perl system(cmd) 和 `cmd` 的区别探讨

    在perl中系统调用有两种方式,一种是system(cmd),另一种是`system`以前一直没注意,这两种方式的区别,还以为是一样的,今天写脚本的时候,忽然想要获取命令的返回值,然后,用了my $r ...

  7. 216. Combination Sum III

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  8. 黄聪:C#如何通过MeasureString、Graphics获取字符串的像素长度

    1.    使用g.MeasureString()获得 使用MeasureString测量出来的字符宽度,总是比实际宽度大一些,而且随着字符的长度增大,貌似实际宽度和测量宽度的差距也越来越大了.查了一 ...

  9. hadoop mapred-queue-acls 配置(转)

    hadoop作业提交时可以指定相应的队列,例如:-Dmapred.job.queue.name=queue2通过对mapred-queue-acls.xml和mapred-site.xml配置可以对不 ...

  10. GC学习笔记

    GC学习笔记 这是我公司同事的GC学习笔记,写得蛮详细的,由浅入深,循序渐进,让人一看就懂,特转到这里. 一.GC特性以及各种GC的选择 1.垃圾回收器的特性 2.对垃圾回收器的选择 2.1 连续 V ...