본문 바로가기

분류 전체보기120

[Java/Python] 문법 비교 정리 #7 자료구조 - HashMap(Dictionary) Python에서 이야기하는 Dictionary 자료 구조는 타 언어에서는 HashMap이라는 명칭으로 사용되나 두개의 명칭 모두 동일한 자료 구조를 가지고 있습니다. 공통적인 특징으로는 key, value의 한쌍의 형태를 띄고 있으며 중복되는 key를 허용하지 않습니다. Java에서의 HashMap // HashMap 선언 Map map = new HashMap(); map.put("name", "a"); map.put("age", 100); map.put("name", "b"); // 처음 대임된 a -> b로 변경 됩니다. // 결과 // key : name, value : b // key : age, value : 100 for (Object o : map.keySet()) { System.out... 2022. 11. 9.
[Java/Python] 문법 비교 정리 #6 자료구조 - Set Java에서의 Set Set a = new HashSet(Arrays.asList(1, 3, 2, 4, 8, 9, 0)); Set b = new HashSet(Arrays.asList(1, 3, 7, 5, 4, 0, 7, 5)); // 합집합 Set union = new HashSet(a); union.addAll(b); System.out.println(union); // 0, 1, 2, 3, 4, 5, 7, 8, 9 // 교집합 Set intersection = new HashSet(a); intersection.retainAll(b); System.out.println(intersection); // 0, 1, 3, 4 // 차집합 Set difference = new HashSet(a); diff.. 2022. 11. 8.
[Java/Python] 문법 비교 정리 #5 자료구조 - Queue, Stack Java에서의 Queue, Stack 1. Queue // queue 선언 방법 1 Queue queueLinkedList = new LinkedList(); queueLinkedList.add(1); queueLinkedList.add(2); queueLinkedList.add(5); queueLinkedList.add(4); queueLinkedList.add(3); // FIFO 유지 : queueLinkedList -> 1,2,5,4,3 //------------------------------------------------- // queue 선언 방법 2 Queue priorityQueue = new PriorityQueue(); priorityQueue.add(1); priorityQueue.. 2022. 11. 7.
[Java/Python] 문법 비교 정리 #4 자료구조 - List Java에서의 리스트 // 1. ArrayList - 조회성으로 많이 사용하는 리스트 List arrList = new ArrayList(); // 2. LinkedList - 데이터 조회보다는 인자를 insert/delete가 많이 일어나는 경우 사용하는 리스트 List linkList = new LinkedList(); // 가장 많이 사용하는 메서드 정리 arrList.add(1); // 1을 저장 arrList.remove(1); // 1을 삭제 arrList.size(0); // 리스트의 크기 확인 arrList.indexOf(1); // 1이 있을 경우 해당 인덱스를 반환, 없을 경우 -1을 반환 두개의 리스트 모두 자주 사용하지만 성능 이슈로 목적에 맞게 사용해 주어야 합니다. Python에.. 2022. 11. 4.