본문 바로가기

JAVA23

String 문자열 비교시 equals(), hashcode() 오버라이딩 이유 equals()와 hashCode()의 비교 방식**equals()는 문자열 **값(내용)을 비교합니다. // "hello"와 "hello"가 서로 다른 메모리 주소에 있더라도, equals()는 그 안에 담긴 문자열의 내용(h, e, l, l, o 순서)이 같은지를 비교해서 true를 반환합니다.**hashCode()는 주소를 직접 비교하는 것이 아닙니다. // hashCode()는 문자열의 **값(내용)**을 기반으로 **해시 코드(정수 값)**를 생성합니다. String 클래스에서 hashCode()는 문자열 내용을 가지고 특정 알고리즘에 따라 고유한 숫자를 만듭니다. 이 숫자가 같으면 내용이 같다고 볼 수 있는 확률이 높다는 것을 의미합니다.헷갈릴 수 있는 부분일반적인 객체(Object 클래스에서.. 2025. 7. 20.
5. Optional에 대한 설명 nullPointException 예외가 발생하는 곳에서 사용하면 된다.import java.util.List;import java.util.Optional;import java.util.function.Predicate;public class PlayingWithOptional { public static void main(String[] args) { List fruits = List.of("apple", "banana", "mango"); fruits.stream() .filter(fruit -> fruit.startsWith("b")) .forEach(System.out::println); Predicate predicate = fruit -> fruit.startsWith(".. 2024. 10. 1.
4. 함수형 문법 사용한 예제 2 1. 짝수를 제곱으로 출력홀수를 세제곱으로 출력import java.util.List;public class FP01Exercises { public static void main(String[] args) { List numbers = List.of(12,9,13,4,6,2,4,12,15); printSquaresOfEvenNumberInLisFunctional(numbers); printCubeOfOddNumberInLisFunctional(numbers); } private static void printSquaresOfEvenNumberInLisFunctional(List numbers) { numbers.stream() .filter(number -> number%2 == 0.. 2024. 10. 1.
3. 함수형 문법을 사용한 예제 1. String을 모두 출력하는 법2. Spring이 포함된 글만 출력하는 법3. 글자의 길이가 4이상만 출력하는 법public class FP01Exercises { public static void main(String[] args) { List courses = List.of("Spring" , "Spring Boot", "API", "Microservices", "AWS", "PCF", "Azure","Docker", "Kubernetes"); courses.stream() .forEach(System.out::println); courses.stream() .filter(course -> course.contains("Spring")) .forEach(Sy.. 2024. 10. 1.
2. 함수형 문법 사용 filter() 1. 짝수만 호출하는 일반적인 방법 import java.util.List;public class FP01Structured { public static void main(String[] args) { List numbers = List.of(12, 9, 13,4,6,2,4,12,15);// printAllNumberInListStructured(numbers); printEvenNumberInListStructured(numbers); } private static void printAllNumberInListStructured(List numbers) { // How to loop the numbers? for(int number : numbers) { System.out.prin.. 2024. 10. 1.
1. 함수형 자바 문법 Stream() 1. 기본적인 for문을 활용한 출력 방법import java.util.List;public class FP01Structured { public static void main(String[] args) { pringAllNumberInListStructured(List.of(12, 9, 13,4,6,2,4,12,15)); } private static void pringAllNumberInListStructured(List numbers) { // How to loop the numbers? for(int number : numbers) { System.out.println(number); } }}  2. 함수형 자바를 사용한 출력 방법import java.util.List;pub.. 2024. 10. 1.