반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 인스턴스메소드
- 익명구현객체
- 추상메소드
- 매개변수참조
- 상속
- createTempFile
- 자바
- map에서key와value
- 필드의다형성
- java
- 배열을 문자열
- 구현클래스
- 오버라이딩
- 객체타입확인
- 자동타입변환
- 선택한요소
- find
- 요소
- 람다식
- 상수필드
- 인터페이스의역할
- 디폴트메소드
- 문자열을 배열
- 정적메소드
- 공백 처리
- ZipInputStream
- jQuery
- 타깃타입
- 생성자참조
- 인터페이스
Archives
- Today
- Total
코드지우개
contains(), indexof() 본문
반응형
contains()
contains() : 문자열이나 List에 특정 문자열이 포함되어 있다면 true 없다면 false 리턴 (대문자, 소문자를 구분한다)
//문자열
String str = "HELLO world";
System.out.println( str.contains("world") ); // 출력 : true
System.out.println( str.contains("hello") ); // 출력 : false
----------------------------------------------------------------
//List
List<String> list = new ArrayList<>();
list.add("빨강");
list.add("노랑");
list.add("파랑");
list.add("초록");
System.out.println( list.contains("빨강") ); // 출력 : true
System.out.println( list.contains("보라") ); // 출력 : false
indexof()
indexof( "찾을 특정 문자", "시작할 위치" ) : 특정 문자나 문자열이 앞에서부터 처음 발견되는 인덱스를 반환한다 만약 찾이 못했을 경우 -1을 반환
String str = "hello world";
System.out.println( str.indexof("e") ); // 출력 : 1
System.out.println( str.indexof("l") ); // 출력 : 2
System.out.println( str.indexof("f") ); // 출력 : -1
System.out.println( str.indexof("l", 5) ); // 출력 : 10
반응형
'java' 카테고리의 다른 글
추상 클래스 (0) | 2023.03.30 |
---|---|
다형성과 상속 (0) | 2023.03.10 |
HashMap에서 Key, Value 꺼내기 (0) | 2023.03.10 |
split() : 문자열 -> 배열, join() : 배열 -> 문자열 (0) | 2023.03.07 |
StringUtils 문자열/공백 처리 (0) | 2023.03.07 |
Comments