How to print the length in array?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raitoHiong
    New Member
    • Nov 2013
    • 7

    How to print the length in array?

    Code:
    public class Array {
    
    	   public static void main (String[] args)
    	   {
    	   String [] sign = new String[]{"Fire", "Earth", "water"};
    	     
    	      System.out.print(sign.length);
    	   
    	}
    }
    i want to print the length of the string which is located at the second element of the array. My output should be 2. how to get it? thanks :)
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    I dont know how to get 2 but try:
    Code:
    System.out.print(sign[1].length());
    This will print the length of 'Earth'

    Comment

    Working...