JAVA StringMethod

JuHyung Yoon·2023년 4월 28일
0

문자열의 길이를 구해주는 메소드 - length

name.length()

문자열을 구성하는 문자들이 같은지 비교하는 메소드 - equals

name.equals("momo")

대소문자 변환 메소드 - toUpperCase , toLowerCase

System.out.println(address.toUpperCase());		
System.out.println(name.toLowerCase());

예외로 isUpperCase, isLowerCase 가 있음 대문자인지 소문자인지 구분하여 bollean값을 리턴

문자열의 특정 위치의 문자 1개를 가져오기 - charAt

	int i =0;
	System.out.println("name.charAt(0) = " + name.charAt(i));

contains - 특정 단어(문자열)이 포함되어 있는지 검색

System.out.println(email.contains("gmail"));

startsWith, endsWith - 맨앞 또는 맨뒤에 문자열검색

System.out.println(email.startsWith("com"));
System.out.println(email.endsWith("kor"));

indexof, lastIndexof - 찾는 문자열의 위치를 리턴

System.out.println(클래스명.indexOf("str 찾고싶은문자열", int어느 위치부터 찾고싶은지));

replace - 문자열 치환

클래스명.replace("kor", "KOREA");

substring - 특정범위 문자열로 추출

클래스명.substring(22);
클래스명.substring(22, 35);
profile
ㅋㅎ딩초보

0개의 댓글