Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 删除重复字符串| Regex |模式匹配器_Java_Android_String - Fatal编程技术网

Java 删除重复字符串| Regex |模式匹配器

Java 删除重复字符串| Regex |模式匹配器,java,android,string,Java,Android,String,我对Java编程相当陌生,还在学习。我已通过正则表达式成功地从url的im捕获中删除“?”。但是,我从中提取图像的网站有多个同名图像实例,因此返回重复字符串 如何删除重复的字符串 我从网站捕获图像和名称的代码: 字符串结果=null try { result = task.execute("https://www.therichest.com/top-lists/top-100-richest-celebrities").get(); String[] s

我对Java编程相当陌生,还在学习。我已通过正则表达式成功地从url的im捕获中删除“?”。但是,我从中提取图像的网站有多个同名图像实例,因此返回重复字符串

如何删除重复的字符串

我从网站捕获图像和名称的代码:

字符串结果=null

    try {
        result = task.execute("https://www.therichest.com/top-lists/top-100-richest-celebrities").get();
        String[] splitResult = result.split("<div class='wp-pagenavi'>");

        Pattern p = Pattern.compile("srcset=\"(.*?)\\?q");
        Matcher m = p.matcher(splitResult[0]);


        while (m.find()) {
            celebURLs.add(m.group(1));
            System.out.println(m.group(1));
        }

        p = Pattern.compile("alt=\'(.*?)Net");
        m = p.matcher(splitResult[0]);

        while(m.find()) {
            celebNames.add(m.group(1));
            System.out.println(m.group(1));
        }
试试看{
结果=任务。执行(“https://www.therichest.com/top-lists/top-100-richest-celebrities).get();
字符串[]splitResult=result.split(“”);
模式p=Pattern.compile(“srcset=\”(.*?\\?q”);
Matcher m=p.Matcher(splitResult[0]);
while(m.find()){
添加(m组(1));
系统输出println(m.group(1));
}
p=Pattern.compile(“alt=\'(*Net”);
m=p.matcher(splitResult[0]);
while(m.find()){
celebNames.add(m.group(1));
系统输出println(m.group(1));
}

最简单的方法是将所有的名字粘在一个集合中,然后在完成后遍历集合。集合的功能将过滤掉重复的名字