public String[] datosAleatorios(T[] a, int tamaño) { ArrayList<String> aux = new ArrayList(); String[] b = new String[tamaño]; Random rnd = new Random(); int i = 0; T elem = a[rnd.nextInt(a.length)]; while (i < tamaño) { if (!aux.contains(elem.toString())) { aux.add(elem.toString()); i++; } elem = a[rnd.nextInt(a.length)]; } return aux.toArray(b); }
public static <T> String fmtList(final List<T> list) { String result = ""; for (T item : list) { result += item.toString() + "\n"; } return result; }
public <T> void logMany(final PrintStream stream, final Collection<T> list) { final String[] a = new String[list.size()]; int i = 0; for (T e : list) { a[i++] = e.toString(); } Arrays.sort(a); for (String o : a) { stream.println(o); } }