Java program to print the length of all strings from a given array
Codeaft.java
class Codeaft
{
    public static void main(String args[])
    {
        System.out.println("———————————————————————————————————————————");
        System.out.println("Program to print strings and its length");
        System.out.println("———————————————————————————————————————————");
        String s[]={"Mouse","Keyboard","Processor","Pen Drive","Joystick"};
        System.out.println("Array contains the following strings"+"\n{");
        
        for(String arr:s)
        System.out.println("   "+arr);
        System.out.println("}\n");
        
        for(int i=0;i<s.length;i++)
        System.out.println(s[i]+" "+s[i].length());
        
        System.out.println("———————————————————————————————————————————");
    }
}
Output
codeaft@codeaft:~$ javac Codeaft.java
codeaft@codeaft:~$ java Codeaft ——————————————————————————————————————————— Program to print strings and its length ——————————————————————————————————————————— Array contains the following strings { Mouse Keyboard Processor Pen Drive Joystick } Mouse 5 Keyboard 8 Processor 9 Pen Drive 9 Joystick 8 ——————————————————————————————————————————— codeaft@codeaft:~$
Comments and Reactions