2022-10-06 1. 방법 [[1, 2, 3], [2, 1], [1, 2, 4, 3], [2]] 이와 같은 이중 배열이 있다고 가정해보자. 이를 내부의 배열의 길이의 순서대로 정렬하면, [[2], [2, 1], [1, 2, 3], [1, 2, 4, 3]] 이런 모양이 나올 것이다. 방법을 알아보자. import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; @Test public void test17() { //오름차순 정렬 Comparator c = new Comparator() { public int compare(L..
2022-10-03 1. 방법 @Test public void test8() { String s = "hello"; for(int i = 0; i < s.length(); i++){ StringBuilder sb = new StringBuilder(s); String subString = sb.substring(0, i); sb.delete(0,i); sb.append(subString); System.out.println(sb.toString()); } } //출력결과 //hello //elloh //llohe //lohel //ohell 위와 같은 방법을 사용하면 처음에 위치한 char를 맨뒤로 보내면서 해당 문자열을 회전 시킬 수 있다. 사실 로직은 한번씩 StringBuilder 를 초기화 시키면..
2022-09-24 1. 방법 사실 직접 구현할 필요 없이 아래와 같은 Integer.bitCount(i) 라는 메소드를 사용하면 빠르고 쉽게 구할 수 있다. int num = 12345; int cntBit = Integer.bitCount(num); System.out.println(cntBit); //6 메인 이미지 출처 : Photo by Geio Tischler on Unsplash
2022-09-23 1. 방법 //String 에서 a 라는 문자의 개수를 세는 방법 String abc = "aaaaabbbbcccc"; int aCount = abc.length() - abc.replace("a", "").length(); 위와 같은 방식으로 " 전체 문자열 길이 - (전체 문자열에서 a를 제외한 문자열의 길이 ) " 와 같은 공식을 사용하면 해당 문자열에서 자신이 찾고자 하는 문자의 개수를 확인할 수 있다. 메인 이미지 출처 : Photo by Slashio Photography on Unsplash
2022-09-02 단순 메일 발송이 아닌 첨부파일 그중에서 엑셀 파일과 함께 발송하는 방법을 알아보자. 우선적으로 구현 class는 총 3개이며, 메일 계정 인증 유틸 / 메일 발송 유틸 / 실제 메일을 발송하는 컨트롤러 이렇게 구성했다. 0. 라이브러리 자신의 build.gradle 아래 2가지의 라이브러리를 추가해야 한다. // 엑셀관련 workbook 라이브러리 // https://mvnrepository.com/artifact/org.apache.poi/poi implementation group: 'org.apache.poi', name: 'poi', version: '5.2.2' // https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml ..
2022-08-23 1. 방법 @Test public void arraytoSet() { String [] arr = {"a", "b", "c"}; Set arrSet = new HashSet(Arrays.asList(arr)); System.out.println(arrSet.toString());//[a, b, c] } 2. 응용 @Test public void arraytoSet() { String [] arr = {"a", "b", "c"}; Set arrSet = new HashSet(Arrays.asList(arr)); System.out.println(arrSet.toString()); String [] arr2 = {"d", "d", "a"}; for(int i = 0; i < arr2.le..