Search a String Array in Java?

后端 未结 2 1458
终归单人心
终归单人心 2021-01-20 23:01

How do I search a string array with start with keyword?

for example,

String[] str = { \"abcd\", \"abdc\", \"bcda\"};

when my search str

2条回答
  •  礼貌的吻别
    2021-01-20 23:36

    String[] strArray = {"abcd", "abdc", "bcda"};
    for (String s : strArray)
        if (s.startsWith(searchTerm))
            System.out.println(s);
    

    Swap startsWith for contains you wish to simply look for containment.

提交回复
热议问题