Java-标识最后有特殊字符的字符串

Java-标识最后有特殊字符的字符串,java,string,Java,String,在迭代时有一个字符串列表,我试图识别包含任何特殊字符的字符串的最后一个字符 for (TermSuggestion.Entry entry : termSuggestion.getEntries()) { for (TermSuggestion.Entry.Option option : entry) { String suggestText = option.getText().string(); if (Character.isAlphab

在迭代时有一个字符串列表,我试图识别包含任何特殊字符的字符串的最后一个字符

for (TermSuggestion.Entry entry : termSuggestion.getEntries())
{ 
    for (TermSuggestion.Entry.Option option : entry)
    { 
        String suggestText = option.getText().string();
        if (Character.isAlphabetic(suggestText.charAt(suggestText.length()))
        {
            System.out.println("Print String--->  "+result);
        }
    }
}
例如:

Apple,
Apple
Apple(
Apples.
Apples
预期结果:

Apple
Apples
请在下面找到我的代码,我只是将特殊字符替换为“”(空),但我想删除字符串本身

for (TermSuggestion.Entry entry : termSuggestion.getEntries()) { 
    for (TermSuggestion.Entry.Option option : entry) { 
        String suggestText = option.getText().string();
        String result = suggestText.replaceAll("[-+.^:,]()","");
        System.out.println("Print String--->  "+result);
    }
}

您可以使用此正则表达式
*[a-z]$
仅过滤以小写/小写字符结尾的单词。

您可以使用它来确定它是否是特殊字符。可以使用获取最后一个字符

for (TermSuggestion.Entry entry : termSuggestion.getEntries())
{ 
    for (TermSuggestion.Entry.Option option : entry)
    { 
        String suggestText = option.getText().string();
        if (Character.isAlphabetic(suggestText.charAt(suggestText.length()))
        {
            System.out.println("Print String--->  "+result);
        }
    }
}
要删除该字符串,首先您的集合必须是可修改的。在您的情况下,它是
术语建议
,因此请确保它是,否则请复制一份。
然后,使用
迭代器
并通过调用
hasNext()
next()
进行迭代。点击要删除的字符串后,调用
remove()
方法。请参阅迭代器文档:

以下带有Streams和apache.commons.lang3的代码

List<String> strings = Arrays.asList("Apple", "Apple", "Apple", "Apples.", "Apples");
String[] alphabet = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
List<String> result = strings.stream().filter(item -> StringUtils.endsWithAny(item, alphabet)).distinct().collect(Collectors.toList());
List strings=Arrays.asList(“苹果”,“苹果”,“苹果”,“苹果”,“苹果”,“苹果”);
字符串[]字母={“a”、“b”、“c”、“d”、“e”、“f”、“g”、“h”、“i”、“j”、“k”、“l”、“m”、“n”、“o”、“p”、“q”、“r”、“s”、“t”、“u”、“v”、“w”、“x”、“y”、“z”};
列表结果=strings.stream().filter(item->StringUtils.endsWithAny(item,alphabet)).distinct().collect(Collectors.toList());

smallercase字符exact@Michael一些国家(或地区:)确实使用小写字母表示较低的字母case@Yogesh_D之所以称之为“小写”,是因为印刷机操作员有不同的大写和非大写块集。非大写字母的使用频率最高,因此使用频率较低,因为它们更容易到达。这与房子的大小无关characters@Michael当然,我的意思是小写,我想这太早了——我没有意识到it@Michael直到为什么小写。需要将此提交给r/TodayiLearn:)我想使用regex和matches比键入所有字符要简单一点我们显然可以混合这里提供的所有解决方案来实现最性感的解决方案:)