ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด/JAVA

[JAVA] contains() ๋ฉ”์†Œ๋“œ

NaNaRin๐Ÿ™ƒ 2021. 1. 15. 22:13

docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/String.html#contains(java.lang.CharSequence)

 

String (Java SE 15 & JDK 15)

All Implemented Interfaces: Serializable, CharSequence, Comparable , Constable, ConstantDesc public final class String extends Object implements Serializable, Comparable , CharSequence, Constable, ConstantDesc The String class represents character strings.

docs.oracle.com


java.lang.String.contains(CharSequence)

 

public boolean containsโ€‹(CharSequence s)

 

๋งค๊ฐœ๋ณ€์ˆ˜ CharSequence :

CharSequence ๋ฌธ์ž์—ด์ด ํฌํ•จ๋˜์–ด์žˆ๋Š”์ง€ ํ™•์ธ

 

๋ฐ˜ํ™˜๊ฐ’ boolean :

ํฌํ•จ๋˜์–ด์žˆ์œผ๋ฉด true, ํฌํ•จ๋˜์–ด์žˆ์ง€ ์•Š์œผ๋ฉด false 

 

 

String.contains(str)

 


์˜ˆ์ œ

public class ContainsEx {

	public static void main(String[] args) {
		String str1 = "ABCDEFG";
		String str2 = "HIJKLMN";
		
		System.out.println(str1.contains("ABC"));
		System.out.println(str2.contains("ABC"));
	}
}

 

์ถœ๋ ฅ

true
false

 

 

์‚ฌ์šฉ ์˜ˆ : nanarin.tistory.com/51