-
Notifications
You must be signed in to change notification settings - Fork 2
Generics Useful Imports
ychenxuan123 edited this page Apr 12, 2021
·
9 revisions
- use Arrays.sort to sort the primitive array after importing Arrays
- use Arrays.asList(arrayName).stream() #convert array to a list before you can create stream.
- creates a mutable list of type E, common functions are add, get, remove, forEach, etc...
- can be used with Comparator as well with method -> void sort(Comparator<? super E> c)
- override compareTo(method in Comparable), to affect the way items are sorted, for natural ordering
- override compare method, to compare two items of any class, allows comparison of two items of generic class
- used to implement Collections.sort methods to sort
- acts like a dictionary in python
- put method to put items in dictionary, get method to get value of a certain key
- Try to use map interface when creating hashmaps, to enable flexible switching between maps in a code
- Predicate, Consumer, BiFunction
- creates a queue of type E objects where you can use add, remove, or poll(removes and returns highest priority item) methods
- can be used with Comparator as well, to make elements order w.r.t. the comparator passed in
- Import Queue as well to use poll() or peek()! (useful in project)
- to use the optional class and methods in optionals
- IntStream is the primitive specialization of Stream, and includes more specific functions (.average(), .sum())
- Convention is to start from a newline after every operation called
Note: Please help to add more useful imports or correct any mistakes :)