/ Published in: Java
FIll a List with ASCII (0-127) characters with a given number of characters.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private List<Character> initCharacterList(int numberOfCharacters, int asciiStart, int asciiEnd) { // first ensure ascii table values assertTrue("asciiStart is invalid", asciiStart >= 0 && asciiStart < asciiEnd); assertTrue("asciiEnd is invalid", asciiEnd <= 127 && asciiEnd > asciiStart); List<Character> list = new ArrayList<>(); int asciiPos = asciiStart; for (int i = 0; i < numberOfCharacters; i++) { list.add(c); asciiPos++; if (asciiPos > asciiEnd) { asciiPos = asciiStart; } } return list; }