一: Hastset根据hashcode判断是否重复,数据不会重复 Java代码 /** List order not maintained **/ public static void removeDuplicate(ArrayList arlList) { HashSet h = new HashSet(arlList); arlList.clear(); arlList.addAll(h); } 二: 通过Hashset的add方法判断是否已经添加过相同的数据,如果已存在相同的数据则不添加
例1: public class Test { public static void main(String[] args) { String s = "'sds gdasda" + "\n" + "edaeafd'"; System.out.println("转换前:"+s); s = s.replaceAll("\r|\n", ""); System.out.println(&quo
public class Hello { public static void main(String[] args){ String text = "12v 4 6 5 55";// 获取用户输入文本 StringBuilder strBuilder = new StringBuilder();// 创建字符串构建器 for (int i = 0; i < text.length(); i++) {// 遍历字符串 char charAt = text.charAt(i);//