Here you can find the source of toString(Iterable extends Object> objects, String sep)
Parameter | Description |
---|---|
objects | an iterable of objects |
sep | a separator string |
public static String toString(Iterable<? extends Object> objects, String sep)
//package com.java2s; import java.util.Iterator; public class Main { /**//from w w w . j a v a 2s. co m * Returns a string that contains all objects separated with the given * separator. * * @param objects * an iterable of objects * @param sep * a separator string * @return a string that contains all objects separated with the given * separator */ public static String toString(Iterable<? extends Object> objects, String sep) { StringBuilder builder = new StringBuilder(); Iterator<? extends Object> it = objects.iterator(); if (it.hasNext()) { builder.append(it.next()); while (it.hasNext()) { builder.append(sep); builder.append(it.next()); } } return builder.toString(); } }