티스토리 뷰

배열

랜덤으로 값 추출

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class xx {
 ...
String[] Pool = {"1", "2", "3"};
List<String> Shuffle = Arrays.asList(Pool);
Shuffle.get(리스트순서번호).toString()


문자열

문자열 길이

sentence.length();

문자열 출력

System.out.printf("%d, %s, %c",1,"문장을 입력",'a');
System.out.println("문장");

문자열 입력받기

.next()
공백을 기준으로 문자, 문자열을 입력받음
.nextLine()
문자, 문자열 한 줄을 입력받음
.nextInt()
정수값을 받음
import java.util.Scanner;
 ...
public class xx {
 ...
Scanner scanner = new Scanner(System.in);
sentence = scanner.next();
sentence = scanner.nextLine();
sentence = scanner.nextInt();

특정 문자 기준으로 문자열 자르기

sentence.split(" ");

한 문자씩 문자열 자르기

sentence.toCharArray();

소문자로 치환

sentence.toLowerCase();

문자열 조회

.indexOf(찾을 문자)
값이 없을 경우 -1을 리턴
sentence.indexOf("word");


댓글
링크
최근에 달린 댓글
«   2024/05   »
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
Total
Today
Yesterday