Answers for "java loop string"

12

java iterate over a string

String scientistName = "Isaac Newton";
 
for (int i = 0; i < scientistName.length(); i++) {
    System.out.print(scientistName.charAt(i) + " "); // I s a a c   N e w t o n
}

//*********************************************************
// you can cast a string into a char[]
String str = "strings are not primitive types!";
 

for (char ch : str.toCharArray()) {
    	System.out.print(scientistName.charAt(i) + " ");
    }
}
Posted by: Guest on March-20-2020
6

java loop through string

String s = "...stuff...";

for (int i = 0; i < s.length(); i++){
    char c = s.charAt(i);        
    //Process char
}
Posted by: Guest on March-29-2020
1

loop through string in java

String s = "...stuff...";

for (int i = 0; i < s.length(); i++){
    char c = s.charAt(i);        
    //Process char
}
Posted by: Guest on February-14-2021
0

loop and save letters in a string java

StringBuilder phone = new StringBuilder();
for (int i = 0; i < number.length(); i++){
    if (Character.isLetter(number.charAt(i))){
        phone.append(getNumber(Character.toUpperCase(number.charAt(i))));
    }else{
        phone.append(number.charAt(i));
    }
}

System.out.println("Your number is " + phone.toString());
Posted by: Guest on January-04-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language