백엔드/Java

    [Java] 배열 정렬(Arrays)

    jdk1.7 이상부터 지원 https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html 예제 array는 int[] array = {3, 17, 1, 39, 8, 41, 2, 32, 99, 2}; 을 받은 값 1. 오름차순 정렬 사용 메소드 : public static void sort(Object[] a) Arrays.sort(array) 사용 (default 오름차순) 파라미터는 primitive type (int, byte, float..), Object(객체 포함) 예제 public static void main(String[] args) { int[] array = {3, 17, 1, 39, 8, 41, 2, 32, 99, 2}; Arrays..

    [Java] 소수 반올림(Math.round, String.format)

    반올림을 할 수 있는 대표적인 방법 2가지 Math.round() String.format() 1. Math.round(), Math.ceil(), Math.floor() Math.round() : 반올림하는 경우 사용 Math.ceil() : 올림하는 경우 사용 Math.floor() : 버림하는 경우 사용 예제 double pie = 3.14159265358979; //반올림 System.out.println(Math.round(pie)); //결과 : 3 System.out.println(Math.round(pie*100)/100.0); //결과 : 3.14 System.out.println(Math.round(pie*1000)/1000.0); //결과 : 3.142 //올림 System.out.p..

    [Java] Generic 제너릭 타입 - 개념,사용법,활용법

    클래스 class Test{ private T t; public void set(T t) { this.t = t; } public T get() { return t; } } 아래는 Method Generic Type 사용법이다. 메소드 제너릭 타입은 Class에 Generic Type을 선언하지 않고, 각 메소드마다 Generic Type을 선언해 사용할수 있다. 아래의 코드 처럼 메소드의 파라미터의 T 이 선언되어 있다면, 리턴타입 바로앞에 제너릭 타입을 선언해주어야한다. ※ 메소드의 파라미터에 가 선언되어 있다면, ReturnType 앞에 를 선언하자. class TestMethod { public static List method(List list, T item) { list.add(item); r..

    [Java] Parameter... 표현

    spring 공부를 하는 도중 prameter에 ... 표현이 있어서 확인해 본 결과 같은 타입을 배열로 받아서 몇개를 쓰든 입력 할 수 있게 해주는 역할인 것 같다. 출처: java.ihoney.pe.kr/155 Parameter... 표현(동일한 파라메터를 여러개 받을 때, 자동으로 배열처리) public void given(String message, Object... args) { .... } 이건 어디서 어떻게 쓰는 표현인고? 찾기 : http://today.java.net/pub/a/today/2004/04/19/varargs.html ellipsis (...) identifies a variable num.. java.ihoney.pe.kr package honeymon.java.study;..