Primitive types swap method will never work because Java is strictly Pass-By-Value. If you want to swap two arguments, use array or object to send reference as a value. Example I primitive types are never changed class Main { //primitive type doesn't swap public static void swap(int i, int j) { int temp = i; i = j; j = temp; } public static void main(String[] args) { int i = 10; int j = 20; swap..
Array.sort() sort the Array in ascending order Example Code import java.util.Arrays; public class Main { public static void main(String[] args) { int arr[] = {2,7,1,9,7}; for (int number : arr) { System.out.print(number); //27197 } // sorting array Arrays.sort(arr); System.out.println("\nSorted numbers are"); for (int number : arr) { System.out.print(number); //12779 } } }
HashMap HashMap is not thread-safe which allows you faster speed than HashTable. HashMap doesn't allow insertion order. *Use LinkedHashMap to preserve the fixed order. key doesn't allow duplicate key, but for value, duplication is allowed. put() - key, value map에 입력 get() - key를 전달해야 그 key의 value가 반환된다. remove() - 해당 key의 key와 value 삭제 Example Code import java.util.*; public class Main { public ..
Map - getOrDefault(key, Default-value) If the key is already mapped with a specified value, return the value, or return the default value if no value is associated with any key. 특정 key가 특정 value와 map 되어있다면 해당 value를 리턴하고 map이 안되어 있을 경우 default value를 리턴한다. Example code import java.util.*; public class Main { public static void main(String[] args) { String[] fruit = {"apple", "banana", "apple", "..
file.close() should be outside of while loop otherwise java.io.EOFException occur. You should place close() in finally. public void readFile() throws ClassNotFoundException { if (!dataFile.exists()) //생성한 파일이 존재하지 않으면 return return; ObjectInputStream in = null; //try 구문 바깥에 선언해줘서 다른 scope 에서도 사용가능하게 해준다! try { BufferedInputStream fileIn = new BufferedInputStream (new FileInputStream(dataFile)); ..
- Total
- Today
- Yesterday
- 알고리즘
- Collection Framework
- spring boot application
- ... in Javascript
- compareTo()
- C++
- hackerrank solution
- 프로그래머스 알고리즘
- Javascript Algorithm
- repeat()
- substring()
- Object type casting
- equals()
- hackerrank javascript
- hackerrank javascript solution
- java
- hackerrank
- easy algorithm
- rest parameter
- code refactoring
- string class in java
- javascript
- 프로그래머스
- easy javascript algorithm
- 프로그래머스 알고리즘문제
- math.max
- algorithm
- HashMap
- math.abs
- HackerRank Algorithm
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |