본문 바로가기

Language/Java16

자바에서의 Hash 보호되어 있는 글 입니다. 2023. 4. 9.
static 블럭의 사용 static block 이란? 클래스 변수를 초기화시키는 용도의 블럭으로 클래스 변수가 로드될 때 바로 실행된다. public class CryptoCurrency { public static Map map = new HashMap(); static { map.put("BTC", "Bitcoin"); map.put("ETH", "Ethereum"); map.put("ADA", "ADA"); map.put("POT", "Polkadot"); } } 프로세스 클래스 로딩 클래스 변수 메모리 생성 선언된 static 블럭 순서대로 실행 https://www.geeksforgeeks.org/static-blocks-in-java/ Static Blocks in Java - GeeksforGeeks A Compu.. 2022. 9. 13.
Thread의 생성과 실행 프로세스와 스레드 Process 프로세스란 사용자가 작성한 프로그램이 운영체제에 의해 메모리 공간을 할당받아 실행중인 것을 말하며 단순히 실행중인 프로그램이라고 할 수 있다. 프로세스는 프로그램에 사용되는 데이터,메모리 등의 자원과 스레드로 구성된다. Thread 스레드란 프로세스 내에서 실제 작업을 수행하는 주체를 말하며 모든 프로세스에는 한 개 이상의 스레드가 작업을 수행한다. 스레드의 생성과 실행 스레드는 아래 두 가지 방법을 통해 생성할 수 있으며 스레드를 통해 작업하고 싶은 내용을 run() 메서드에 작성하면 된다. Runnable 인터페이스 구현 Thread 클래스 직접 인스턴스화 필요 Thread 클래스 상속 Thread 클래스 직접 인스턴스화 하지 않음 class ThreadWithClas.. 2022. 7. 19.
Stream의 여러 예제들 다른 클래스에 있는 요소의 평균 값 구하기 public class Solution { public double Average(List students) { double answer = members.stream() .filter(n -> n.getGender().equals("Male"))//(1) .mapToInt(Student::getAge)//(2) .average()//(3) .orElse(0.0);//(4) return answer; } static class Student { String name; String gender; int age; public Member(String name, String gender, int age) { this.name = name; this.gender = g.. 2022. 7. 19.
Stream 최종 연산 1. 요소의 출력 : forEach() 2. 요소의 소모 : reduce() 3. 요소의 검색 : findFirst(), findAny() 4. 요소의 검사 : anyMatch(), allMatch(), noneMatch() 5. 요소의 통계 : count(), min(), max() 6. 요소의 연산 : sum(), average() 7. 요소의 수집 : collect() 2022. 7. 19.
Stream 중간 연산 주요 메서드 스트림 필터링 : filter(), distinct() 스트림 변환 : map(), flatMap() 스트림 제한 : limit(), skip() 스트림 정렬 : sorted() 스트림 연산 결과 확인 : peek() 스트림 필터링 .filter() : .distinct() : 해당 스트림에서 중복된 요소가 제거된 새로운 스트림 return IntStream stream1 = IntStream.of(7, 5, 5, 2, 1, 2, 3, 5, 4, 6); IntStream stream2 = IntStream.of(7, 5, 5, 2, 1, 2, 3, 5, 4, 6); // 스트림에서 중복된 요소를 제거함. stream1.distinct().forEach(e -> System.out.print(.. 2022. 7. 19.