Thứ Tư, 13 tháng 5, 2020

Java note

1. String concatenation

Với những case đơn giản thì ko cần thiết phải sử dụng StringBuilder
Trong java, String object thì immutable - nghĩa là 1 khi đã tạo là ko thể thay đổi.
Ví dụ:
String str= "Hello";
String str1= str+ " World";

LinkedList: insert new element ở đầu và ở giưã good.

Kết luận:

a. you should use an ArrayList if you need random access to elements in the list, especially if your use case could result in large lists.
b. If you intend to make many insertions and deletions particularly if you make them at the beginning or in the middle of the list, then a LinkedList would make more sense
2. Queue - First in - First out
3. Tree - Binary Tree is common
1 element có tối đa 2 con

binary search tree:

elements “less than” the value of a given node are children on the left, and elements “greater than” the value of a given node are children on the right.

4. Tree Map and Hash Map

TreeMap the order of the keys is preserved when iterating over the whole collection, because the collection is stored in order.
This isn’t possible with a HashMap, because the keys are stored dependent on the object’s hashCode
LinkedHashMap same HashMap, -> so element retrieval will be O(1)

5. SET

A set is an unordered collection of objects that does not contain any duplicates.

happy coding

thelam92

0 nhận xét:

Đăng nhận xét