if (useinvoicess != null && useinvoicess .size() > 0) {
useinvoice = String.valueOf(useinvoicess).replaceAll(" ", "").replace("[", "").replace("]","");
for (int i = 1; i < useinvoicess.size(); i++) {
int a = useinvoicess.get(i);
if(useinvoicess.contains(a-1) && useinvoicess.contains(a+1)){
useinvoice=useinvoice.replaceAll(a+",","-");
}
}
while (useinvoice.contains("--")) {
useinvoice=useinvoice.replaceAll("--","-");
}
useinvoice=useinvoice.replaceAll(",-","-");
System.out.println(useinvoice);
}