일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- stream groupingby
- github CI
- equals override
- github ec2 deploy
- javascript image slider
- AliasFor
- java stream api
- github deploy
- java hashCode
- github action codedeploy
- list remove
- kotest
- image slider
- equals
- c++ 빌드
- 코드포스
- github action
- java CompletableFuture
- lombok Builder
- Spring Aspect
- github CI/CD
- Java
- java 비동기처리
- AWS Codedeploy
- Java Wrapper Class
- vanilla js image slider
- Java lombok
- hashcode override
- SpringBootApplication
- Github action deploy
- Today
- Total
목록JAVA (10)
기록창고
한 객체를 만들 때, 두가지 이상 생성자가 있을 수 있다. public class Something { int A; int B; int C; public Something() {} @Builder public Something(int A, int B, int C) { this.A = A; this.B = B; this.C = C; } @Builder public Something(SomethingDto dto) { this.A = dto.getA(); this.B = dto.getB(); this.C = dto.getC(); } } 이렇게 되면 Something something = Something.builder().build(); Intellij 기준 아래 A, B, C 에 대한 자동완성이 안생긴다 ..
개인 프로젝트 하던 중, 외부에서 받아온 데이터를 가공해야하는 일이 생겼다. 이런식으로 데이터를 받아온다. { "operatorpvp_roundlost:3:F:infinite": 18, "operatorpvp_headshot:3:8:infinite": 21, "operatorpvp_death:3:A:infinite": 37, "operatorpvp_death:4:1:infinite": 421, .. } 아래는 모든 입력이다. 더보기 { "operatorpvp_roundlost:3:F:infinite": 18, "operatorpvp_headshot:3:8:infinite": 21, "operatorpvp_death:3:A:infinite": 37, "operatorpvp_death:4:1:infinite..
Spring boot 개인 프로젝트 할 때, 다른 사이트의 API 를 요청해야 할 필요가 있었습니다. 레인보우식스 라는 게임의 Rank 정보를 가져와야 하는데 region와 season을 파라미터로 가지고 있고, region 은 3개, season 1 ~ 17(현재시즌) 까지 조회를 하여 플레이어의 전체 시즌정보를 가져와야했습니다. 하나씩 for 문으로 돌리니 51개의 요청이 생성되고, 응답이 올때까지 기다려야 다음 포문을 실행하기 때문에 응답시간이 되게 오래걸렸습니다 for(int season = 1; season
자바의 기본형(Primitive type)이 있습니다. boolean, char, short, int, long, float, double 입니다 그리고 위의 기본형을 감싼 클래스가 제공되죠 Boolean, Character, Short, Integer, Long, Float, Double Class 입니다. Double doubleWrap = 1.2; // Double doubleWrap = new Double(1.2); 와 같은 표현 -> new Double 은 deprecated 되었다고 합니다. // 대신 static method로 Double.valueOf(1.2); 를 권장한다고 하네요 Double reference 에 자세히 나와있습니다 위의같은 경우 AutoBox에 의해서 a에 1.2 do..
문자열을 비교할 때는 이렇게 사용했다. String str = "Something"; if(str.equalsIgnoreCase("something)) { System.out.println("str is same"); } 그치만 만약 str이 null 이라면..? 위에서는 String str = "Something" 이렇게 명시적으로 선언해줬기 때문에 바로 알 수 있지만 public String checkSameStr(String str) { if(str.equalsIgnoreCase("Something)) { /* logic */ } else { } } 위와 같은 함수를 만들어서 사용할 수 있다. 그렇지만 함수 인자로 받은 str 가 null 이 아니라는 보장이 없다. 그래서 str이 null인 상태에..
Todo List 웹를 만드는 도중 DB 에서 가져온 데이터를 현재 진행 현황에 맞춰서 분리해서 보여줘야할 때가 있었다. public class TodoDto { private int id; private String title; private String step; } // getter 와 setter 와 constructor는 모두 구현되어있다고 가정한다. DB 쿼리는 전부를 가져오는 쿼리문이였따. SELECT * FROM todo; 쿼리를 step 별로 던지면 안해도 됐을 거 같지만 .... 처음 코드는 모두를 가져와서 iterator를 돌면서 step 에 맞게 list 에 추가했다. List todoList = getList(); // 전부를 가져온다. List doingList = new Arr..
List 에 있는 목록 중 원하는 객체를 삭제하는 방법. 맨 처음에는 가장 간단하게 for문으로 돌리면서 찾아서 삭제를 했다. import java.util.*; public class test { public static void main(String[] args) { List list = new ArrayList(); list.add("A"); list.add("A"); list.add("B"); list.add("C"); list.add("D"); list.add("E"); for(int i=0;i A B C D E 0 1 2 3 4 5 -> 0 1 2 3 4 이렇게 변경되어, i 는 1로 변경된다. 그래서 두번째 A는 발견되지 않고 삭제가 되지 않는다. for(int i=0;i i-- } // B..
이전 Post에서 hashCode를 오버라이드했음에도 불구하고 set의 사이즈가 2로 나왔다. 이유를 HashMap의 getNode 함수에서 찾을 수 있다. public V get(Object key) { HashMap.Node e; return (e = this.getNode(hash(key), key)) == null ? null : e.value; } final HashMap.Node getNode(int hash, Object key) { HashMap.Node[] tab; HashMap.Node first; int n; if ((tab = this.table) != null && (n = tab.length) > 0 && (first = tab[n - 1 & hash]) != null) { Ob..
Map이나 Set에서 key 값을 저장할 때 해쉬를 해서 저장을 한다. hash를 하기 위해서, Object class 안에 있는 hashCode() 라는 함수를 사용합니다. public native int hashCode(); 함수는 이렇게 생겼고 뭔지 모르겠지만, int 값을 반환하는 것을 알 수 있습니다. 그래서 Object 마다 모두 hashCode()를 사용할 수 있고, 실제로 hashCode를 통해 해쉬하는 것을 볼 수 있습니다. 아래 코드는 HashMap에 구현되어있는 코드입니다. put 을 할때 key를 hash하여 넣는 것을 볼 수 있습니다 public V put(K key, V value) { return this.putVal(hash(key), key, value, false, tru..
Static => 정적 멤버 Static 이 붙은 변수나 메소드는 객체가 만들어지기 전에도 호출하여 사용할 수 있다. class A{ public static int staticValue = 10; public static void staticMethod(){ System.out.println("Static Method"); } } public class Main { public static void main(String[] args) { System.out.println(A.staticValue); // 10 A.staticMethod(); // Static Method } } 위처럼 A라는 클래스가 있지만 A라는 클래스를 가지고 만든 객체가 없어도 사용할 수 있다. 그리고 Static Method는 ..