在Java中从数组/集的每个元素中剥离字符

时间:2015-12-25 05:24:02

标签: java arrays string set

我有一个打印如下的HashSet:

[Category:Porch of the Cathedral of Palermo, Category:Side views of the Cathedral of Palermo, Category:Church towers of the Cathedral of Palermo, Category:Saint Rosalia by Vincenzo Vitaliano, Category:Piazza del Duomo (Palermo)]

我需要删除"类别:"关闭集合中每个元素的字符,以产生输出:

[Porch of the Cathedral of Palermo, Side views of the Cathedral of Palermo, Church towers of the Cathedral of Palermo, Saint Rosalia by Vincenzo Vitaliano, Piazza del Duomo (Palermo)]

最简单的方法是什么(在Java中)?我目前正在使用HashSet(需要它来确保元素是唯一的)但我可以将它转换为ArrayList或任何最适合此任务的东西。

1 个答案:

答案 0 :(得分:1)

最简单的方法是:用空字符串替换"Category:"。您已拨打toString()的{​​{1}}。

HashSet

输出:

System.out.println(set.toString().replace("Category:", ""));