ETC

Stream

List<Integer> nums = -something-;
nums = nums.stream()
    .map(n -> n * 2)
    .filter(n -> n >= 0)
    .collect(Collectors.toList());

ASCII code

  • A ~ Z : 65 ~ 90

  • a ~ z : 97 ~122

Math

Math.max(n1, n2);
Math.min(n1, n2);
Math.abs(n);
Math.pow(base, exponent);
Math.sqrt(n);
Math.round(n);
Math.floor(n);
Math.ceil(n);

Comparator

public class MySort implements Comparator<int[]>{
       public int compare(int[] a, int[] b){
             return a[0]-b[0];
       }
 }

Iterator

Iterator itr = array_name.iterator(); //or list.iterator()

itr.hasNext(); //returns bool
itr.next();
itr.remove(); //removes curr element

Integer

Integer.MIN_VALUE;
Integer.MAX_VALUE;

%10, /10

  • 언제 사용하는지 직감적으로 느끼기.

    • Coding Bat에 예제 있음.

Random

Random r = new Random();
r.nextInt(n); //return a random int from 0 to n

// OR

Math.random(); //returns a random double between 0.0 and 1.0

Java 정수의 최대/최소값

static int Integer.MAX_VALUE
static int Integer.MIN_VALUE

Last updated