ArrayList

  • add(int idx)
  • remonve(int idx)
  • size()

Pair로 Queue 구현

class Pair {

            int x, y;

            Pair(int x, int y) {

                        this.x = x;

                        this.y = y;

            }

 

            @Override

                public void compareTo(Pair pair) {

                      return Integer.compare(this.x, pair.x);

               }

}

Queue<Pair> queue = new LinkedList<>();

queue.add(new Pair(x, y));

Pair t = queue.poll();

PriorityQueue<Pair>pq = new PriorityQueue<>();
pq.add(new Pair(start, 0));
while(!pq.isEmpty()){
	Pair now = pq.poll();
}

 

int[] arr = new int[n];

Arrays.sort(arr);

Arrays.sort(arr, Collections.reverseOrder());

 

String to Int

  • Integer.parseInt(“123”)

Int to String

  • Integer.toString(123)
  • String.valueOf(123)

Integer.compare(1, 2); // 왼쪽 작으면 -1

Integer.compare(2, 2); // 같으면 0

Integer.compare(2, 1); // 왼쪽 크면 1

String.charAt('a') != 'b' // char는 '==' , '!=' 비교로 가능

 

str.substring(int beginIndex, int endIndex) -> begin ~ end-1까지의 값을 리턴

str = str.replaceAll("0", "1") //str에 0을 다 1로 바꾸기

 

int[] -> length

String -> length()

 

// String 정렬
String str = "basde";
char[] arr = str.toCharArray();  //String -> char[]
Arrays.sort(arr); //String, char[] 둘다 정렬 가능
String result = new String(arr); //char[] -> String
System.out.println(result);

+ Recent posts