I want create a list with alphabets with each alphabets for 5 times. I tried a code and it worked,
public class AlphabetsTest {
public static void main(String[] args) {
List<Character> alphabetList = new ArrayList<>();
for (int i=0; i<3; i++){
char chr='a';
if (i==1)
chr = 'b';
if (i==2)
chr = 'c';
for (int j=0; j<5; j++){
alphabetList.add(chr);
}
}
}
}
But I would have to add multiple if conditions for more alphabets. Is there any better way to avoid it.