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

How to use ArrayList.addAll()?

Collections.addAll is what you want. Collections.addAll(myArrayList, ‘+’, ‘-‘, ‘*’, ‘^’); Another option is to pass the list into the constructor using Arrays.asList like this: List<Character> myArrayList = new ArrayList<Character>(Arrays.asList(‘+’, ‘-‘, ‘*’, ‘^’)); If, however, you are good with the arrayList being fixed-length, you can go with the creation as simple as list = Arrays.asList(…). Arrays.asList … Read more

How to find out if letter is Alphanumeric or Digit in Swift

For Swift 5 see rustylepord’s answer. Update for Swift 3: let letters = CharacterSet.letters let digits = CharacterSet.decimalDigits var letterCount = 0 var digitCount = 0 for uni in phrase.unicodeScalars { if letters.contains(uni) { letterCount += 1 } else if digits.contains(uni) { digitCount += 1 } } (Previous answer for older Swift versions) A possible … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)