You can use the containment method contains
. If it exists, it returns true. If it does not exist, it returns false.
Code examples are as follows: (Related learning video tutorial sharing: java video tutorial)
package com.jianhu.Test; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; public class Test01 { public static void main(String[] args) { List list = new ArrayList(); list.add("12"); list.add("35"); list.add("46"); boolean bool = list.contains("12"); boolean bool2 = list.contains("41"); System.out.println(bool);//true System.out.println(bool2);//false } }
Recommended related article tutorials: java introductory tutorial
The above is the detailed content of How to determine whether a string exists in a list collection in java. For more information, please follow other related articles on the PHP Chinese website!