I'm trying to split strings by capital letters, for example when the string is "SizeColorSize", the aoutput array is: {"Size", "Color", "Size"}. This works normally. Now I want to remove the duplicates from the array and that's why I am using HashSet, so that I would have ["Color", "Size"] sorted collection. Then I am printing the output in MySQL table.
But the problem is that in the output I have one extra comma : [, "Color", "Size"].
Any idea why is it like that?
This is the part of the code:
for (int j = 0; j < configPair.size(); j++) {
r = configPair.get(j).split("(?=\p{Lu})");
for (int i = 0; i < r.length; i++) {
r = new HashSet<String>(Arrays.asList(r)).toArray(new String[0]);
r[i].trim();
Arrays.sort(r);
Set<String> mySet = new HashSet<String>(Arrays.asList(r));
sqlAttributeConfig = "INSERT INTO Config_Attributes (Config_Pairs) VALUES ('"
+ mySet + "')";
System.out.print(r[i]);
}
System.out.println();
r = null;
con.stmt.executeUpdate(sqlAttributeConfig);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…