How can I create a String ArrayList with a repeated group of strings like
"A", "B", "C", "A", "B", "C", "A", "B", "C", "A", "B", "C", ......
In Python I use
list = deque(["A","B","C"]*288) # 288 times "A","B","C"
You could use an IntStream to create a range of 288 items, and then flatmap it to though three strings:
List<String> strings = IntStream.range(0, 288)
.boxed()
.flatMap(i -> Stream.of("A", "B", "C"))
.collect(Collectors.toList());
Without complicating things, Use a simple for loop:
ArrayList<String> alphabets = new ArrayList<String>();
for (int i=0; i<288; i++) {
alphabets.add("A");
alphabets.add("B");
alphabets.add("C");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With