如何在Java字符串中重复删除重复的字符? [英] How can I de-duplicate repeated characters in a Java string?
本文介绍了如何在Java字符串中重复删除重复的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Java中是否存在一种方法,它允许您将之类的字符串转换为________ _______
到 how_are_you
,即只保留一个 _
重复时。
Does there exist a method in Java which lets you transform a string like how________are_______you
to how_are_you
, i.e. just keep one _
when it is duplicated.
推荐答案
使用regexp replacer:
Use regexp replacer:
string.replaceAll("_+", "_")
这篇关于如何在Java字符串中重复删除重复的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文