src/main/java/com/zandero/utils/StringUtils.java
public static String join(List<?> list, String separator, Integer limit) {

		if (separator == null || separator.equalsIgnoreCase("")) {
			throw new IllegalArgumentException("Missing separator!");
		}

		StringBuilder output = new StringBuilder();
		if (limit == null || limit <= 0) {
			limit = list.size();
		}

		if (list != null && limit > 0) {
			for (int i = 1; i <= limit; i++) {

				if (i > list.size()) {
					break;
				}

				if (i <= limit) {
					output.append(list.get(i - 1));

					if (i == limit && list.size() > limit) {
						// ok list is larger than limit .. and we hit the limit
						output.append(separator)
						      .append("... [")
						      .append(limit)
						      .append("/")
						      .append(list.size())
						      .append("]");
					}

					if (i < limit) {
						output.append(separator);
					}
				}
			}
		}

		return output.toString();
	}
public static String join(List<?> list, String separator, Integer limit) {

		if (separator == null || separator.equalsIgnoreCase("")) {
			throw new IllegalArgumentException("Missing separator!");
		}

		StringBuilder output = new StringBuilder();
		if (limit == null || limit <= 0) {
			limit = list.size();
		}

		if (list != null && limit > 0) {
			for (int i = 1; i <= limit; i++) {

				if (i > list.size()) {
					break;
				}

				if (i <= limit) {
					output.append(list.get(i - 1));

					if (i == limit && list.size() > limit) {
						// ok list is larger than limit .. and we hit the limit
						output.append(separator)
						      .append("... [")
						      .append(limit)
						      .append("/")
						      .append(list.size())
						      .append("]");
					}

					if (i < limit) {
						output.append(separator);
					}
				}
			}
		}

		return output.toString();
	}
public static String join ( List < ? > list , String separator , Integer limit ) { if ( separator == null || separator . equalsIgnoreCase ( "" ) ) { throw new IllegalArgumentException ( "Missing separator!" ) ; } StringBuilder output = new StringBuilder ( ) ; if ( limit == null || limit <= 0 ) { limit = list . size ( ) ; } if ( list != null && limit > 0 ) { for ( int i = 1 ; i <= limit ; i ++ ) { if ( i > list . size ( ) ) { break ; } if ( i <= limit ) { output . append ( list . get ( i - 1 ) ) ; if ( i == limit && list . size ( ) > limit ) { // ok list is larger than limit .. and we hit the limit output . append ( separator ) . append ( "... [" ) . append ( limit ) . append ( "/" ) . append ( list . size ( ) ) . append ( "]" ) ; } if ( i < limit ) { output . append ( separator ) ; } } } } return output . toString ( ) ; }
Joins list of string items to a single string, where items are separated
with a defined separator.

@param list      to join into string
@param separator to be used between elements
@param limit     max items to consider when joining, null or 0 to join all
@return items joined into a single string
Joins list of string items to a single string where items are separated with a defined separator .