∙Java
JAVA 코딩테스트 기본 지식
NearAndDear
2022. 4. 28. 21:52
반응형
* 형변환
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
public class Main {
public static void main(String[] args) throws Exception {
int a = 65;
System.out.println("Integer to Character : " + (char) a); //A
System.out.println("Integer to String : " + String.valueOf(a)); //65
char ch = '3';
char[] ch2 = {'a','b'};
System.out.println("Character to Integer : " + ((int) ch - '0')); //3
System.out.println("Character to String : " + String.valueOf(ch)); //3
System.out.println("Character to String : " + String.valueOf(ch2)); //ab
String s = "9";
String s2 = "123";
System.out.println("String to Integer : " + Integer.parseInt(s)); //9
System.out.println("String to Character : " + s.charAt(0)); //9
System.out.println("String to Character : " + Arrays.toString(s2.toCharArray())); // [1, 2, 3]
}
}
|
cs |
스텍
Stack<Integer> stack = new Stack<>(); //int형 스택 선언
push
pop
큐
Queue<Integer> queue = new LinkedList<>();
add
poll
우선순위 큐
PriorityQueue<Integer> pq = new PriorityQueue<>();
add
pop
peek
Array
int[] arr = new int[4];
Arrays.sort();
Arrays.sort(arr, Collections.reverseOrder());
arr.length
ArrayList
ArrayList<Integer> alist = new ArrayList<>();
add
remove
get
alist.size();
String[] array = arrayList.toArray(new String[arrayList.size()]); // ArrayList -> Array
ArrayList<String> arrayList = new ArrayList<>(Arrays.asList(array)); // Array -> ArrayList
HashSet
HashSet hs = new HashSet<>();
add(key)
contains(key)
HashMap
HashMap<String, Integer> hm = new HashMap<>();
put(key, value)
get(key)
containsKey(key)
반응형