How to find strings in String array that ends with specified substring in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        try {

            String[] arr = {"next", "subtext", "java"};

            for (String val : arr) {

                if (val.endsWith("ext")) {
                    System.out.println(val);
                }
            }

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
           
run:
     
next
subtext
  
 */

 



answered Nov 22, 2016 by avibootz
...