I am looking for a method to reverse an array
of char
s.
If I use an ArrayList<Character>
to store my chars, I can use the Collections.reverse(List<T>)
-method.
List<Character> list = new ArrayList<>();
for (int i = 0; i < 26; i++) {
list.add((char) (97 + i));
}
Collections.reverse(list);
But how can I reverse an array
of char
s? Is there any API-method or do I have to implement it by myself? Collections.reverse(Arrays.asList(char[]))
is useless.
char[] input = {'a', 'b', 'c', 'd', 'e'};
char[] out = new char[input.length];
for (int i = 0; i < input.length; i++) {
out[i] = input[input.length-i-1];
}
Thanks.