TIL
-
[TIL] 자료구조5 - 해시테이블 사용하기TIL 2024. 10. 5. 21:08
자바 해시테이블 메서드 정리하기 HashMap map = new HashMap(); //해시테이블 생성map.put("Apple", 10); // "Apple" key에 10 추가 (추가, 수정 모두 가능)map.put("Apple", 20); // "Apple" key의 value을 20으로 수정map.put("Apple", 30); // "Apple" key의 value을 30으로 수정map.remove("Apple"); // "Apple" key와 그에 해당하는 value을 제거Integer value = map.get("Banana"); // "Banana" key에 해당하는 value 검색map.containsKey(key) //특정키가 존재하는 지 확인
-
[TIL] java 우선순위큐TIL 2024. 9. 20. 23:49
우선순위큐:우선순위가 존재하는 큐. 기본적으로 큐는 선입선출형태로 나가지만, 우선순위큐는 우선순위가 높은 순서대로 나가게 된다. 우선순위큐를 쓰는이유:자동 정렬되므로, 최소값, 최대값을 쉽게 관리할 수 있다. 여러 이벤트 중에서 우선순위가 높은 이벤트를 먼저 처리해야 할 때 사용된다예시: 프로세스 스케줄링에서 우선순위가 높은 작업을 먼저 처리하는 경우. 우선순위 큐를 다루는 메서드 PriorityQueue pq = new PriorityQueue(); // 선언방식1 (오름차순 기본값.)PriorityQueue pq = new PriorityQueue(Collections.reverseOrder()); //(내림차순으로 선언)pq.add(); // 값 삽입pq.offer(); // 값 삽입..
-
[TIL] java 문자열 다루는 메서드 정리TIL 2024. 9. 18. 00:02
//String 타입String str = "abcde";str.length() // 5 문자열 길이str.CharAt(0) // 'a' 0번째 글자 가져오기str.subString(a,b) // a부터 b 까지 문자열 일부 가져오기str.equals(a) // 문자열 비교, a와 같은지 비교하기str.equalsIgnoreCase(a) // 문자열 비교, 대소문자 상관x, a와 같은지 비교하기 str.toUpperCase(a) // 문자열 대문자로 변환str.toLowerCase(a) // 문자열 소문자로 변환str.contains(a) // 문자열이 특정 문자열 포함하는지 확인str.replace(a,b) // 문자열 a를 b로 교체하기str.split(a) // 문자열 a를 기준으로 나..
-
[TIL] 쿼리스트링 에러TIL 2024. 8. 28. 12:34
쿼리스트링으로 전달되는 값은 자동으로 문자열로 바뀌어 전달되게 된다. 그렇기 때문에 쿼리스트링에는 별도의 문자열 표시인 따옴표 ''를 쓰면 안된다. 이 따옴표 까지 문자열의 일부로 인식되기 때문에 원하는 결과를 얻지 못하게 될 수 있다. 예시) 관심사에 '여행'이라는 문자열이 들어간 데이터들을 찾아본다고 가정하자 1. {{baseUrl}}/user?search='여행'따옴표 까지 문자열의 일부로 인식되어 원하는 데이터 검색이 안된다. 2. {{baseUrl}}/user?search=여행-> 따옴표가 없어도 문자열로 변환되어 '여행' 값이 들어간 데이터가 검색된다 결론쿼리스트링에는 따옴표를 넣으면 안된다
-
오버라이딩, 오버로딩TIL 2024. 7. 2. 20:50
오버라이딩:메소드 재정의상속으로 인해 동일한 이름의 메소드가 여러개인 경우, 자식 클래스의 메소드만 사용된다. class A{ void paint() { System.out.println("a") }}class B extends A{ void paint() { System.out.println("b") }}A a = new A();B b = new B();A a2 = new B();a.print() // a출력b.print() // b출력a2.print() // b출력 A클래스의 인스턴스 a가 paint()를 호출하면, a가 출력된다B클래스의 인스턴스 b가 오버라이딩된 paint()를 호출하면, b가 출력된다A클래스 타입을가진 B클래스 a2가 오버라이딩된 paint()를 호출하..
-
[TIL] 자료구조 - 배열, 연속리스트, 연결리스트 차이TIL 2024. 6. 26. 21:26
1. 배열 고정된 크기의 연속된 메모리공간에 동일한 크기와 타입의 자료를 저장한다 특징:요소들은 동일한 타입을 가진다크기가 고정되어있고, 변경불가능하다중간 자료가 삭제되면 null값이 들어간다(밀도 != 1) 인덱스 통한 검색 시: ( 시간복잡도: O(1) ) 장점:빠른 인덱스접근이 가능하다메모리 사용효율적이다(연속된 메모리공간) 단점:크기변경이 불가능하다 2.연속 리스트배열과 유사하게 연속된 공간에 자료를 저장하지만 크기 조절이 가능하다 특징:크기조정시, 기존데이터를 옮기는 작업이 필요하다 중간자료가 삭제되면 뒤의 자료들을 앞으로 땡겨온다 (밀도=1 )인덱스 통한 검색시 : O(1)삽입, 삭제시 : O(n) 장점:연속된 메모리공간에 저장되어 빠른접근이가능하다 크기 조절이 가능하다 단점:삽입,..
-
테스트 코드로 알아보는 DITIL 2024. 6. 10. 22:04
서비스를 개발하던 도중 테스트 코드를 작성해야할 필요가 있었고, bcrypt와 같은 외부라이브러리를 사용할때, 함수 모킹이 되지않고, 테스트속도가 오래걸린다는 문제가 있었습니다 (bcrypt와 같은 암호화하는 작업들은 cpu 작업량을 많이요구하고 시간도 오래걸립니다) 문제가 생긴 메서드import * as bcrypt from 'bcryptjs';async signIn(loginDto: LoginDto): Promise { const channel = await this.prisma.channel.findFirst({ where: { id: loginDto.id }, }); if (!channel) { throw new UnauthorizedException(..
-
모듈 분리 / 서비스 코드 분리 기준TIL 2024. 6. 10. 17:26
모듈 분리, 서비스 코드 분리 기준에 대해 생각해보자 각각 언제해야할까? 예를들어 댓글 CRUD기능과 댓글 좋아요기능이 있다고 가정해보자 그럼 1. 댓글 CRUD기능과 댓글 좋아요 기능의 서비스 코드를 분리해야할까? -> 특정 서비스내의 메서드들 중에서 어떤 것은 export를 해야하고 어떤 것은 export를 할 필요가 없다(해서는 안된다). 이때 각 메서드들은 별도의 클래스로 분리해야한다( 객체지향설계 SOLID 중 인터페이스 분리 원칙) (인터페이스 분리 원칙 : 클라이언트가 자신이 이용하지 않는 메서드에 의존하지 않아야 한다는 원칙이다. -> 사용하지않는 불필요한 메서드 들은 가져오면 안된다. 꼭 필요한 메서드들만 주입 받아야한다 ) 2. 댓글 CRUD기능과 댓글 좋아요 기능의..