What is the easiest way to generate a String of n repeated characters?
int n = 10; char[] chars = new char[n]; Arrays.fill(chars, ‘c’); String result = new String(chars); EDIT: It’s been 9 years since this answer was submitted but it still attracts some attention now and then. In the meantime Java 8 has been introduced with functional programming features. Given a char c and the desired number … Read more