public class Test4 {
public static void main(String[] args) {
char[] oldarr = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
String s2 = s2(oldarr);
System.out.println(s2);
}
public static String s2(char[] oldarr) {
int count = 0;
char[] arr2 = new char[4];
while (count < 4) {
int index = (int) Math.floor(Math.random() * oldarr.length);
if (new String(arr2).indexOf(oldarr[index]) == -1) {
arr2[count++] = oldarr[index];
}
}
return new String(arr2);
}
}