Java(129)
-
List<String>에서 중복 데이터 처리 방법
중복 데이터 삭제(차집합)import java.util.ArrayList;import java.util.List;public class RemoveDuplicates { public static void main(String[] args) { List list1 = new ArrayList(List.of("apple", "banana", "orange", "grape")); List list2 = new ArrayList(List.of("banana", "kiwi", "grape", "melon")); // Remove duplicates from list1 that are in list2 list1.removeAll(list2); //..
2024.11.07 -
예외가 발생해도 계속 진행하고, 마지막에 예외 발생하기
public class FileUtils { public static List getFiles(String directory) { try(Stream filePaths = Files.walk(Paths.get(directory))) { return filePaths .filter(Files::isRegularFile) .collect(Collectors.toList()); } catch(IOException e) { e.printStackTrace(); return List.of(); } }}public class Main { public static void main(String[] args) { List files = FileUtils.getFiles(..
2024.11.06 -
Recursive 파일 정보 가져오기
public class FileUtils { public static List getFiles(String directory) { try(Stream filePaths = Files.walk(Paths.get(directory))) { return filePaths .filter(Files::isRegularFile) .collect(Collectors.toList()); } catch(IOException e) { e.printStackTrace(); return List.of(); } }}
2024.11.06 -
String "2024-11-06 11:24:01 +0900"을 Date로 변환
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class DateExample { public static void main(String[] args) { String dateString = "2024-11-06 11:24:01 +0900"; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); try { Date date = formatter.parse(date..
2024.11.06 -
FastAPI에서 이미지 가져오기
Binary를 직접 가져오기pom.xml org.apache.httpcomponents.client5 httpclient5 5.1Spring Boot Codeimport org.springframework.core.io.InputStreamResource;import org.springframework.http.HttpHeaders;import org.springframework.http.MediaType;import org.springframework.http.ResponseEntity;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestParam;impo..
2024.10.19 -
Http 통신하기 Apache HttpClient 사용
pom.xml org.apache.httpcomponents.client5 httpclient5 5.1GET 방식import org.apache.hc.client5.http.classic.methods.HttpGet;import org.apache.hc.client5.http.classic.methods.CloseableHttpResponse;import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;import org.apache.hc.client5.http.impl.classic.HttpClients;import org.apache.hc.core5.http.io.entity.EntityUtils;public class HttpClientEx..
2024.10.19