Home  >  Article  >  Java  >  How to determine whether a string exists in a list collection in java

How to determine whether a string exists in a list collection in java

王林
王林Original
2019-12-31 16:59:5212198browse

How to determine whether a string exists in a list collection in java

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn