I'm working on a while-loop which should check a text and see if letters are in CAPS or not as well as if they are vowels etc. I'm not sure of how to create a variable which can store certain letters. I asked this question yesterday an was told to use Array, but im wondering theres anyway to do this with help of Strings,charAt.
Asked
Active
Viewed 611 times
2 Answers
1
You can do this without a loop :-
String s = "HELLO";
if(s.toUpperCase().equals(s)){
System.out.println("String is All-CAPS!");
}

dumbPotato21
- 5,669
- 5
- 21
- 34
-
But in this case you should know that after call s.toUpperCase() String s will be changed to UpperCase – Vugar Suleymanov Mar 17 '17 at 07:43
-
@VugarSuleymanov No, it won't. `Strings` are **immutable**. [here](http://stackoverflow.com/questions/1552301/immutability-of-strings-in-java) – dumbPotato21 Mar 17 '17 at 07:44
0
Yes you can just iterate over the String with charAt() for every position. If you have a String text:
for(int i = 0; i < text.length() ; i++){
char currentChar = text.charAt(i);
doSomething(currentChar);
}

leurer
- 441
- 3
- 10