String (List<CharSequence> list, String delimiter) { StringJoiner joiner = new StringJoiner(delimiter); long toSkip = 2; Set<CharSequence> uniqueValues = new HashSet<>(); boolean first = true; for (CharSequence charSequence : list) { if (first) { first = false; continue; } if (uniqueValues.add(charSequence)) { if (toSkip > 0) { toSkip--; continue; } joiner.add(charSequence); } } return joiner.toString(); }