public class Test {
public static void main(String[] args) {
String[] shops = {"DE", "CH", "AT", "NL", "FR", "DK", "ES", "IT", "EN", "SE", "NO", "FI", "PT", "BE", "LU", "RO", "GR", "CZ", "PL", "HU"};
String shopsForTest = (shops[new Random().nextInt(shops.length)]) + "+" + (shops[new Random().nextInt(shops.length)]) + "+" + (shops[new Random().nextInt(shops.length)]) +
"+" + (shops[new Random().nextInt(shops.length)]) + "+" + (shops[new Random().nextInt(shops.length)]);
System.out.println(shopsForTest);
}
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
class Scratch {
public static void main(String[] args) {
String[] shops = {"DE", "CH", "AT", "NL", "FR", "DK", "ES", "IT", "EN", "SE", "NO", "FI", "PT", "BE", "LU", "RO", "GR", "CZ", "PL", "HU"};
List<String> shopList = Arrays.asList(shops);
Collections.shuffle(shopList);
String result = shopList.stream().limit(5).collect(Collectors.joining("+"));
System.out.println(result);
}
}
String[] shops = { "DE", "CH", "AT", "NL", "FR", "DK", "ES", "IT", "EN", "SE", "NO", "FI", "PT", "BE", "LU",
"RO", "GR", "CZ", "PL", "HU" };
List<String> list = new ArrayList<String>(Arrays.asList(shops));
StringBuilder builder = new StringBuilder();
int count =0;
while (count < 5) {
Random r = new Random();
int rand = r.nextInt(list.size());
builder.append(list.get(rand)).append(" ");
list.remove(rand);
count++;
}
String shopsForTest = builder.toString();
System.out.println(shopsForTest);
public class Test {
public static void main(String[] args) {
StringBuilder builder = new StringBuilder();
List shops = new ArrayList();
shops.add("DE");
shops.add("CH");
shops.add("AT");
shops.add("NL");
shops.add("FR");
shops.add("DK");
shops.add("ES");
shops.add("IT");
shops.add("EN");
shops.add("SE");
shops.add("NO");
shops.add("FI");
shops.add("PT");
shops.add("BE");
int index = 0;
for (int x = 0; x < 5; x++) {
Random random = new Random();
index = random.nextInt(shops.size());
System.out.println(shops.get(index));
// shops.remove(index);
}
String shopsForTest = shops.get(index) + "+";
System.out.println(shopsForTest);
}
}