전체 글
-
[Java] 스트림의 중간연산Java 2022. 2. 9. 00:01
이전 시간에 스트림의 생성에 대해서 알아보았습니다 https://junuuu.tistory.com/78?category=968252 스트림은 아래와 같은 주기를 가집니다. 1. 스트림 생성 2. 중간 연산 (0~ n번) 3. 최종 연산 (0~1번) 오늘은 중간 연산에 대해 알아보겠습니다 스트림 자르기 Stream skip(long n) Stream limit(long maxSize) IntStream intStream = intStream.rangeClosed(1, 10) ; // 1~10의 요소를 가진 스트림 생성 intStream.skip(3).limit(5).forEach(System.out::print); //45678 skip() 과 limit() 은 스트림의 일부를 잘라낼 때 사용합니다. sk..
-
[백준] 1260 : DFS와 BFS - 자바(JAVA)알고리즘/백준 2022. 2. 8. 00:01
https://www.acmicpc.net/problem/1260 1260번: DFS와 BFS 첫째 줄에 정점의 개수 N(1 ≤ N ≤ 1,000), 간선의 개수 M(1 ≤ M ≤ 10,000), 탐색을 시작할 정점의 번호 V가 주어진다. 다음 M개의 줄에는 간선이 연결하는 두 정점의 번호가 주어진다. 어떤 두 정점 사 www.acmicpc.net 문제 해석 그래프를 DFS로 탐색한 결과와 BFS로 탐색한 결과를 출력해야 한다. 방문할 수 있는 정점이 여러개면 정점 번호가 작은것이 우선순위이다. 정점 번호는 1번부터 N번까지이다. 입력 첫째 줄에 정점의 개수, 간선의 개수, 탐색을 시작할 정점의 번호 V가 주어진다. 제약조건 정점의 개수 N : 1
-
[Java] Math.max() vs 삼항연산자Java 2022. 2. 7. 00:01
두 숫자를 비교하기 위해 Math.max() 메서드를 사용하거나, 삼항 연산자를 사용하거나, if-else문을 사용합니다. 이중에 if-else는 코드가 길어지기 때문에 제외하고 삼항연산자와 Math.max() 메서드 중 어떤 것이 더 빠를까(효율적일까) 궁금점이 생겨서 알아보게 되었습니다. 우선 내부적으로 Math.max() 메서드가 어떻게 이루어지는지 살펴보겠습니다 public static int max(int a, int b) { return (a >= b) ? a : b; } 내부적으로 삼항연산자를 사용하여 return 합니다. 따라서 실행을 테스트해보기 전에도 삼항 연산자가 조금 더 빠를 것 같다고 예상해 볼 수 있습니다. 실제로 Math.max() 메서드와 삼항연잔자를 20억 번 테스트해보겠습..
-
얼리 리턴 패턴(Early Return Pattern) 이란?클린 코드(Clean Code) 2022. 2. 6. 00:01
얼리 리턴 패턴이란? 함수나 메서드를 작성하는 패턴으로, 예상되는 긍정 결과가 함수의 끝에서 리턴되게 하고 조건이 맞지 않는 경우 나머지 코드는 반환하여 실행을 종료합니다. Ealry Return 말 그대로 리턴을 일찍하여 뒷 코드의 구조를 단순하게 만들어주는 패턴으로 else를 제거하는 것이 목적입니다. 코드를 통하여 더 알아보겠습니다. Early Return 패턴 적용 전 public String returnStuff(SomeObject argument, SomeObject argument2){ if(argument1.isValide()){ if(argument2.isValide()){ SomeObject otherVal1 = doSomeStuff(argument1, argument2) if(othe..
-
테스트 코드 - 회원 관리 예제 실습(회원 도메인과 리포지토리 생성)테스트코드(Test Code) 2022. 2. 5. 00:01
이전에 회원 관리 예제를 작성하는 실습(회원 도메인과 리포지토리 생성)을 진행해 보았습니다. 개발한 기능을 main 메서드를 통해서 실행하거나, 웹 애플리케이션의 컨트롤러를 통해서 해당 기능을 실행하게 되면 준비하고 실행하는데 시간이 오래 걸립니다. 또한 반복적으로 테스트하거나 여러 테스트를 한꺼번에 하기 어렵다는 문제점이 있습니다. 이를 통해 테스트 코드를 작성해보고자 합니다. https://junuuu.tistory.com/75 스프링 부트 - 회원 관리 예제 실습 비즈니스 요구사항 정리 데이터 : 회원 ID, 이름 기능 : 회원 등록, 조회 아직 데이터 저장소가 선정되지 않은 가상의 시나리오(어떤 데이터베이스를 사용할지 정해지지 않음) 일반적인 웹 애플리 junuuu.tistory.com 1. 자바..
-
[백준] 2589번 : 보물섬 - 자바(JAVA)알고리즘/백준 2022. 2. 4. 00:01
https://www.acmicpc.net/problem/2589 2589번: 보물섬 첫째 줄에는 보물 지도의 세로의 크기와 가로의 크기가 빈칸을 사이에 두고 주어진다. 이어 L과 W로 표시된 보물 지도가 아래의 예와 같이 주어지며, 각 문자 사이에는 빈 칸이 없다. 보물 지도의 www.acmicpc.net 문제 해석 직사각형 모양을 가진 보물섬 지도가 존재한다. 지도는 여러 칸으로 나뉘어 있으며 각 칸은 육지(L)나 바다(W)로 표시되어 있다. 지도에서 이동은 상하좌우로 이웃한 육지로만 가능하며, 한 칸 이동하는 데 한 시간이 걸린다. 보물은 서로 간에 최단 거리로 이동하는데 있어 가장 긴 시간이 걸리는 육지 두 곳에 나뉘어 묻혀있다. 보물 지도가 주어질 때, 보물이 묻혀 있는 두 곳 간의 최단 거리로..
-
[Java] Comparator와 Comparable란?Java 2022. 2. 3. 00:01
Arrays.sort()를 호출하면 컴퓨터가 알아서 배열을 정렬하는 것처럼 보이지만, 사실은 Character클래스의 Comparable의 구현에 의해 정렬됩니다. Comparator와 Comprable이란? 모두 인터페이스로 컬렉션을 정렬하는데 필요한 메서드를 정의하고 있습니다. 정렬을 하는 데는 두 가지가 필요합니다. 1. 정렬 대상 2. 정렬 기준 Comparator와 Comparale은 객체 정렬에 필요한 정렬 기준을 제공하는 인터페이스입니다. 인터페이스이기 때문에 Comparable 또는 Comparator를 사용하고자 한다면 인터페이스 내에 선언된 메서드를 반드시 구현해야 합니다. 가장 중요한 것은 Comparable과 Comparator는 객체를 비교할 수 있도록 만듭니다! Comparato..
-
[백준] 1065번 : 한수 - 자바(JAVA)알고리즘/백준 2022. 2. 2. 00:01
https://www.acmicpc.net/problem/1065 1065번: 한수 어떤 양의 정수 X의 각 자리가 등차수열을 이룬다면, 그 수를 한수라고 한다. 등차수열은 연속된 두 개의 수의 차이가 일정한 수열을 말한다. N이 주어졌을 때, 1보다 크거나 같고, N보다 작거나 www.acmicpc.net 문제 해석 어떤 양의 정수 X의 각 자리가 등차수열을 이룬다면 이를 한수라고 한다. 등차수열은 연속된 두 개의 수의 차가 일정한 수열을 말합니다. 이때 1보다 크거나 같고 N보다 작거나 같은 한 수의 개수를 출력하는 프로그램을 만들어야 합니다. 등차수열 예시 1, 3, 5, 7, 9 (차가 2로 일정함) 10, 20, 30, 40, 50 (차가 10으로 일정함) 한수의 예시 123 24 3 15 입력..