private static String listToString(List<Integer> list){
  Collections.sort(list);
  StringBuilder builder=new StringBuilder();
  for (int i=0; i < list.size(); i++) {
    Integer column=list.get(i) + 1;
    if (i < list.size() - 2) {
      builder.append(column);
      builder.append(", ");
    }
 else     if (i == list.size() - 2) {
      builder.append(column);
      builder.append(AND);
    }
 else {
      builder.append(column);
    }
  }
  return builder.toString();
}

private static String listToString ( List < Integer > list ) { Collections . sort ( list ) ; StringBuilder builder = new StringBuilder ( ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { Integer column = list . get ( i ) + 1 ; if ( i < list . size ( ) - 2 ) { builder . append ( column ) ; builder . append ( ", " ) ; } else if ( i == list . size ( ) - 2 ) { builder . append ( column ) ; builder . append ( AND ) ; } else { builder . append ( column ) ; } } return builder . toString ( ) ; }
converts the integer list to a string where the entries are separated by " , " and " and " .
