Iterate through string array in Java

后端 未结 10 892
逝去的感伤
逝去的感伤 2020-11-30 01:21

I have String array with some components, this array has 5 components and it vary some times. What I would like to do is to iterate through that array and get the first comp

10条回答
  •  無奈伤痛
    2020-11-30 02:22

    You can do an enhanced for loop (for java 5 and higher) for iteration on array's elements:

    String[] elements = {"a", "a", "a", "a"};   
    for (String s: elements) {           
        //Do your stuff here
        System.out.println(s); 
    }
    

提交回复
热议问题