/**
* @author lautturi.com
* Java example: count characters in a string array in java
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
String[] strArray = {"hello","lautturi","java","python","world","lau"};
// printing number of words in array
System.out.println("Number of words in array: " + strArray.length);
int lettersCounter=0;
for (int counter = 0; counter < strArray.length; counter++) {
lettersCounter += strArray[counter].length();
}
System.out.println("Number of characters in array:"+lettersCounter);
}
}
output:
Number of words in array: 6 Number of characters in array:31