Compare First 3 Character String with List of String of Each String First 3 Character

后端 未结 5 1288

The Sample Code which needs a solution?

public class TestJJava {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

               


        
5条回答
  •  我在风中等你
    2021-01-26 07:32

    This is what you are supposed to do.

    String first3 = abc.substring(0,3);
    boolean found = false;
    for (String s : lstValues) {
        if (s.startsWith(first3)) {
            found = true;
            break;
        }
    }
    
    if (found) {
        System.out.println("**** Match Found ***");
    } else {
        System.out.println("**** No Match Found ****");
    }
    

    Go through the list checking each entry until you find a match.

提交回复
热议问题