'java'에 해당되는 글 1건

  1. 2022.01.08 코테 유용한 함수 모음 (JAVA)
java2022. 1. 8. 16:47

코테 유용한 함수 모음

 

HashMap<Character,Integer> hm = new HashMap<>();
HashMap<Character,Integer> em = new HashMap<>();

#ex1, 값 얻어오기(default값 지정)
hm.getOrDefault(x, 0);

/*ex2, hashmap의 비교, Sliding window 문제를 해결할 때 유용함. 
설명 :Compares the specified object with this map for equality.  Returns
     {@code true} if the given object is also a map and the two maps
     represent the same mappings.
 */
hm.equals(em);
//ex3) 중복없는 정렬된 리스트가 필요한 경우, TreeSet 사용, 기본 내림차순이므로, 필요한경우 descendingSet() 메소드를 통해 새로운 TreeSet을 리턴 받는다. 
 TreeSet<Integer> hs = new TreeSet<>();
new ArrayList(hs.descendingSet());

 

or 

 

 TreeSet<Integer> hs = new TreeSet<>(Collections.reverseOrder());

'java' 카테고리의 다른 글

출력을 File로 저장  (0) 2022.05.14
BufferedReader + StringTokenizer 예제  (0) 2022.04.25
try with resource 구문 예제 (JAVA 7)  (0) 2019.09.24
Simple UDP server & client socket 예제  (0) 2019.09.22
Simple server & client socket 예제  (0) 2019.09.22
Posted by easy16