if (log == true) { StringBuilder sb = new StringBuilder(); for (int x : a) { if (a[ret[0]] == x) { startLog = true; } if (a[ret[3]] == x) { sb.append(x); sb.append(':'); startLog = false; } if (startLog == true) { sb.append(x); sb.append(' '); } else { sb.append(" "); } if ((a[ret[1]] == x) || (a[ret[2]] == x)) { sb.append(':'); } } System.out.println(sb.toString()); }