Home > Java > JavaBase > 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

王林
Release: 2019-12-31 16:59:52
Original
12324 people have browsed it

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
	}
 
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template