JAVA :: 그 외의 다양한 클래스
📝 StringBuffer 클래스
💬 스트링을 다루는 클래스로서, 내부에 가변 크기의 버퍼를 가지고 문자의 개수에 따라 버퍼 크기를 자동 조절한다.
⚠ 스트링의 수정이 가능하다.
👉 예시
StringBuffer sb = new StringBuffer("This"); // 객체생성
sb.append("is pencil."); // sb = "This is pencil."
sb.insert(7, " my"); // sb = "This is my pencil."
sb.replace(8, 10, "your"); // sb = "This is your pencil."
System.out.println(sb);
👉 결과
This is your pencil.
📝 StringTokenizer 클래스
💬 문자열을 분리하기 위해 사용한다.
💡 구분 문자
💬 문자열을 분리할 때 사용되는 기준 문자
💡 토큰
💬 구분 문자로 분리된 문자열
💡 주요 메소드
👉 예시
import java.util.StringTokenizer;
public class postingex {
public static void main(String[] args) {
String company = "Samsung&Apple&Google";
StringTokenizer st = new StringTokenizer(company, "&");
int n = st.countTokens(); //분리된 토근의 개수
System.out.println("분리된 토큰의 개수 = "+n);
while(st.hasMoreTokens()) // 다음 토근이 있으면 1 없으면 0
{
String token = st.nextToken(); // 분리된 토근 얻기
System.out.println(token);
}
}
}
👉 결과
분리된 토큰의 개수 = 3
Samsung
Apple
Google
📝 Math 클래스
'Math.메소드'
💬 기본적인 산술 연산을 수행하는 메소드를 제공하는 클래스이다.
💡 주요 메소드
⚠ 모든 메소드가 static 타입이다.
💬 random()
👉 예시
for(int i = 0; i < 10; i++)
{
int n = (int)(Math.random()*100 + 1); // 1~100까지의 랜덤 정수
}
Reference
명품 자바 에센셜 (2014, 황기태) / 혼자 공부하는 자바 (2019, 신용권)
Author And Source
이 문제에 관하여(JAVA :: 그 외의 다양한 클래스), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@ro_sie/JAVA-그-외의-다양한-클래스저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)