i've got code that changes lower case latters to upper case and the other way around. What is the faster way of doing it that what i wrote?
public static String flipcase(String text) {
ArrayList<Character> arry2 = new ArrayList<Character>();
char[] array = text.toCharArray();
char x = ' ';
char y = ' ';
for (int i = 0; i <array.length; i++) {
if (Character.isLowerCase(array[i])) {
x = Character.toUpperCase(array[i]);
arry2.add(x);
} else if (Character.isUpperCase(array[i])){
y = Character.toLowerCase(array[i]);
arry2.add(y);
} else if (Character.isSpace(array[i])) {
arry2.add(array[i]);
}
}
StringBuilder result = new StringBuilder(arry2.size());
for (Character c : arry2) {
result.append(c);
}
String output = result.toString();
return output;
}
public static void main(String[] args) {
System.out.println(flipcase("To jest Ten FLIP Case"));
}