Topcit

Java 함수 목록

Life Log 2024. 11. 11. 20:23
728x90
반응형

주요 Java 메서드 목록

Java 시험에서는 표준 라이브러리 메서드에 대한 기본적인 이해와 사용 능력이 요구됩니다. 특히 Java의 표준 라이브러리 클래스 (Math, String, ArrayList 등)에서 자주 사용하는 메서드를 암기하면 시험 대비에 큰 도움이 됩니다.


1. Math 클래스

Java의 Math 클래스는 다양한 수학 계산 메서드를 제공합니다.

메서드 설명 예시
Math.abs(int a) 절댓값 반환 Math.abs(-10)10
Math.max(int a, int b) 최대값 반환 Math.max(5, 10)10
Math.min(int a, int b) 최소값 반환 Math.min(5, 10)5
Math.pow(double a, double b) a의 b 거듭제곱 계산 Math.pow(2, 3)8.0
Math.sqrt(double a) 제곱근 계산 Math.sqrt(16)4.0
Math.round(double a) 반올림 Math.round(5.5)6
Math.ceil(double a) 올림 Math.ceil(5.3)6.0
Math.floor(double a) 버림 Math.floor(5.7)5.0
Math.random() 0.0 이상 1.0 미만의 난수 생성 Math.random()0.12345

2. String 클래스

String 클래스는 문자열을 다룰 때 사용되며, 자주 사용하는 메서드들이 많습니다.

메서드 설명 예시
str.length() 문자열 길이 반환 "hello".length()5
str.charAt(int index) 지정 인덱스의 문자 반환 "hello".charAt(1)'e'
str.substring(int beginIndex) 부분 문자열 반환 "hello".substring(1)"ello"
str.substring(int beginIndex, int endIndex) 부분 문자열 반환 "hello".substring(1, 3)"el"
str.indexOf(String str) 지정 문자열의 인덱스 반환 "hello".indexOf("e")1
str.contains(CharSequence s) 문자열 포함 여부 확인 "hello".contains("ll")true
str.equals(String anotherStr) 문자열 비교 "hello".equals("hello")true
str.toUpperCase() 대문자로 변환 "hello".toUpperCase()"HELLO"
str.toLowerCase() 소문자로 변환 "HELLO".toLowerCase()"hello"
str.trim() 공백 제거 " hello ".trim()"hello"
str.split(String regex) 문자열 분리 "a,b,c".split(",")["a", "b", "c"]

3. ArrayList 클래스

ArrayList는 동적 배열이며, 자주 사용되는 메서드들이 있습니다.

메서드 설명 예시
list.add(E element) 요소 추가 list.add("hello")
list.get(int index) 지정 인덱스의 요소 반환 list.get(0)
list.size() 리스트의 크기 반환 list.size()3
list.remove(int index) 지정 인덱스의 요소 제거 list.remove(0)
list.contains(Object o) 요소 포함 여부 확인 list.contains("hello")true
list.isEmpty() 리스트가 비어 있는지 확인 list.isEmpty()false
list.clear() 리스트의 모든 요소 제거 list.clear()

4. Arrays 클래스

Java의 Arrays 클래스는 배열을 다룰 때 유용한 메서드를 제공합니다.

메서드 설명 예시
Arrays.sort(int[] array) 배열 정렬 Arrays.sort(arr)
Arrays.toString(int[] array) 배열을 문자열로 변환 Arrays.toString(arr)"[1, 2, 3]"
Arrays.equals(int[] a, int[] b) 두 배열이 같은지 비교 Arrays.equals(arr1, arr2)true

5. 기타 자주 사용되는 메서드

System 클래스

  • System.out.println() - 표준 출력
  • System.currentTimeMillis() - 현재 시간 (밀리초)

Scanner 클래스 (입력 받기)

  • scanner.nextInt(), scanner.nextLine()

시험 준비 팁

  • 자주 사용하는 메서드들은 암기하고, 사용법에 익숙해지세요.
  • 간단한 연습 문제를 통해 메서드 사용법을 연습하세요.
  • IDE 없이 코드 작성 연습을 해보세요.
728x90
반응형

'Topcit' 카테고리의 다른 글

상호배제  (0) 2024.11.11
chmod 명령어  (0) 2024.11.11
디자인패턴  (0) 2024.11.11
클라우드 서비스  (3) 2024.11.11
악성 프로그램 및 보안 위협  (0) 2024.11.11