java string count
String line = "Your string here";
String stringToCount = "?";
int count = line.length() - line.replace(stringToCount, "").length();
java string count
String line = "Your string here";
String stringToCount = "?";
int count = line.length() - line.replace(stringToCount, "").length();
How do you count characters in a string array in Java?
package practical5;
import java.util.Arrays;
public class Part1_9 {
public static void main(String[] args) {
// declaring and populating array
String quoteArray[] = { "\"Continuous", "effort", "not", "strength",
"nor", "intelligence", "is", "the", "key", "to", "unlocking",
"our", "potential.\"\n" };
// for loop to print full array
for (int counter = 0; counter < quoteArray.length; counter++) {
System.out.print(quoteArray[counter] + " ");
}// end of for loop
// Printing array using Enhanced for/ for each loop (Different way to
// print array)
for (String element : quoteArray) {
System.out.print(element + " ");
}// end of enhanced for
// line break
System.out.println();
// printing number of words in array
System.out.println("Number of words in array: " + quoteArray.length);
**// printing total number of letters in array**
for (int counter = 0; counter < quoteArray.length; counter++) {
String letters = new String(quoteArray[counter]);
}
// printing the smallest word
// printing the biggest word
}// end of main
}// end of class
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us