반응형
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 |
Tags
- socketio
- error
- linux
- opencv
- tensorflow
- 분당맛집
- TTS
- no space left on device
- pytorch
- 티스토리챌린지
- 터미널
- ROS2
- ubuntu
- ros
- Torch
- CLASS
- ChatGPT
- openAI
- 오블완
- humble
- 판교
- CUDA
- 딥러닝
- timm
- GPT
- python
- string
- 스팸
- 맛집
- Android
Archives
- Today
- Total
RoBoLoG
[Java] List<String>에 여러 단어들이 있는데 그들 중 어떤 String 데이터에 포함된 단어가 있는지 확인하는 방법 본문
Study/Java
[Java] List<String>에 여러 단어들이 있는데 그들 중 어떤 String 데이터에 포함된 단어가 있는지 확인하는 방법
SKJun 2023. 6. 16. 16:56import java.util.ArrayList;
import java.util.List;
public class ListExample {
public static void main(String[] args) {
List<String> words = new ArrayList<>();
words.add("apple");
words.add("banana");
words.add("cherry");
String text = "I Like apple";
for (String word : words) {
if (text.contains(word)) {
System.out.println("'" + word + "'가 포함되었습니다.");
}
}
}
}
위의 예시에서는 words 리스트에 "apple", "banana", "cherry"를 추가하고, text 문자열에 있는 단어들 중에서 words 리스트에 있는 단어가 포함되어 있는지 확인합니다. 만약 포함되어 있다면 해당 단어를 출력합니다.
위 예시에서는 "I Like apple" 문자열을 검색하는 경우를 보여주고 있습니다. 필요에 따라 text 변수에 다른 문자열을 할당하여 원하는 문자열을 검색할 수 있습니다.
728x90
반응형
'Study > Java' 카테고리의 다른 글
[JAVA] 상업적으로 무료 사용 가능한 Android Java TTS 엔진 (0) | 2023.07.04 |
---|---|
[Java] String에서 특정 단어가 포함되었는지 확인하는 방법 (0) | 2023.06.16 |
[Java] Java에서 List<String> 사용 예시 (0) | 2023.06.16 |