/** * @param str 1__#__123@qq.com###12312__#__456456@ddd.com###12212__#__456456@ddd.com### * @return */ public static List<JSONObject> getRowsData(String str){ List<JSONObject> list = new ArrayList<JSONObject>(); str = str.substring(0,str.length()-3); System.out.println(str); String[] arr = str.split("###"); String[] arr2 = new String[arr.length]; //创建一个长度为5的String(字符串)型的一维数组 int i=0; for(String temp : arr){ String[] temp2 =temp.split("__#__"); System.out.println(temp2[0]); System.out.println(temp2[1]); arr2[i] = temp2[1]; i++; } System.out.println(arr2); Map<String, Integer> map = new HashMap<String, Integer>(); for (String str2 : arr2) { Integer num = map.get(str2); num = null == num ? 1 : num + 1; map.put(str2, num); } if (arr.length != map.size()) { System.out.println("存在相同的元素及重复个数!"); } Set set = map.entrySet(); Iterator<Map.Entry> it = set.iterator(); List<String> sList = new ArrayList<String>(); while (it.hasNext()) { Map.Entry<String, Integer> entry = (Map.Entry<String, Integer>) it.next(); String key = entry.getKey(); Integer value = entry.getValue(); System.out.println("String :" + key + " num :" + value); if (value > 1) sList.add(key); } for(String re_email : sList){ System.out.println("计算重复的email是几行 :"); System.out.println("重复的email是 :" + re_email); for(String temp : arr){ String[] temp2 =temp.split("__#__"); if(re_email.equals(temp2[1])){ System.out.println(); JSONObject obj = new JSONObject(); obj.put("msg","第"+temp2[0]+"行,"+re_email+"重复"); //第12行,456456@ddd.com重复 list.add(obj); } } } return list; } String :456456@ddd.com num :2 String :123@qq.com num :1 计算重复的email是几行 : 重复的email是 :456456@ddd.com 第1233行,456456@ddd.com重复 第132行,456456@ddd.com重复
站长微信:xiaomao0055
站长QQ:14496453