Determines whether the comma separated string contains an instance of a number

  • 2020-05-19 04:49:02
  • OfStack

1. First, turn the string into an array of strings

2. Convert the string array to the List collection

3. Use the contains() method in the List set to determine whether a certain number is included


@Test
  public void test2222(){
    String ids = "1,2,3,45,35";
    String[] values = ids.split(",");
    List<String> list = Arrays.asList(values);
    if(list.contains("4")){
      System.out.println("true");
    }else {
      System.out.println("false");
    }
  }

Related articles: