Please enable JavaScript.
Coggle requires JavaScript to display documents.
JAVA INTERMEDIATE (LIST (Collections (Converting Lists into Arrays (java…
JAVA INTERMEDIATE
LIST
java.util.List
Method:
- size()
- isEmpty( )
- get(i)
- set(i, e)
- add(i, e)
- remove(i)
Positional List
Method:
- first()
- last()
- before(position)
- after(position)
- isEmpty()
- size()
- addFirst(element)
- addLast(element)
- addBefore(position, element)
- addAfter(position, element)
- set(position, element)
- remove(position)
-
Iterator
Method
- hasNext(): Returns true if there is at least one additional element in the sequence, and false otherwise.
- next(): Returns the next element in the sequence
- remove(): remove element return when call method next(). It will throw IllegalStateException if the method next() is not called yet, the remove method is already called.
List Iterator
Method:
- add(e)
- previous()
- next()
- hasNext()
- hasPrevious()
- nextIndex()
- previousIndex()
- remove()
- set(e)
Collections
Method:
- copy(L dest , L src )
- disjoint(C, D
- fill(L,e)
- frequency(C, e): Returns the number of elements in the collection C that are equal to e.
- max(C)
- min(C)
- replaceAll(L, e, f )
- reverse(L)
- rotate(L,d)
- shuffle(L)
- sort(L)
- swap(L, i, j)
-
-
-
Map
stores key-
value pairs (k, v),
- Method:
- size()
- isEmpty()
- get(k)
- put(key,value)
- remove(key)
- keySet() Returns all the keys stored in Map
- values(): Returns all the values stores in Map
- entrySet( ): Returns all the key-value entries in Map
-
HashMap and Treemap:
Sort: no | yes
Method: Basic | Rich
Speed: faster | low when comparison
Ordering: No | Yes
init capaticy: yes | no
HashTable
- Method:
- createTable( )
- bucketGet(h, k)
- bucketPut(h, k, v)
- bucketRemove(h, k)
- entrySet( )
LINK LIST
METHOD
- size()
- first() return null if list is empty
- last() return null if list is empty
- isEmpty()
- addFirst()
- addLast()
- removeFirst() return null if list is empty
- removeLast() in doubly linked list
-
Circularly
-
-
Removing an Element
-
Algorithm removeFirst( ):
if head == null then
the list is empty.
head = tail.getNext()
if (tail == head) tail = null
else tail = tail.getNext()
size = size − 1
Doubly
-
-
-
remove a element
Algorithm remove(node)
Node prev = node.getPrev();
Node next = node.getNext();
prev.setNext(next);
prev.setPrev(prev);
size--;
STACK - QUEUE - DEQUES
STACK
Method:
- push(e)
- pop()
- top( )
- size( )
- isEmpty( )
-
QUEUE ADT
Method
- enqueue(e): Adds element e to the back of queue.
- dequeue( ): Removes and returns the first element from the queue
- first( )
- size()
- isEmpty( )
DEQUE ADT
Method:
- addFirst(e)
- addLast(e)
- removeFirst( )
- removeLast( )
- first()
- last()
- size()
- isEmpty()
Tree ADT
Method:
- getElement( )
- root( )
- parent(p)
- children(p)
- numChildren(p): Returns the number of children of position p.
- isInternal(p)
- isExternal(p)
- isRoot(p)
- size()
- isEmpty()
- positions()
- iterator()
Depth and Height
- The depth of p is the number of ancestors of
p
- Ex: root does not has ancestor => depth = 0
- the height of p is one more than the maximum of the heights of
p’s children
- If p is a leaf, then the height of p is 0.
Binary Tree
-
Properties:
- level d has at most 2 d nodes.
Linked Structure
Method
- addRoot(e)
- addLeft(p,e)
- addRight(p,e)
- set(p, e)
- attach(p, T 1 , T 2 )
- remove(p)
Java 8
lambda
-
-
Function<T,R> interface contains the method R apply(T t).
-
Stream API
Interface Summary:
- BaseStream<T,S extends BaseStream<T,S>>
- Collector<T,A,R>
- DoubleStream
- DoubleStream.Builder
- IntStream
- IntStream.Builder
- LongStream
- LongStream.Builder
- Stream<T>
- Stream.Builder<T>
- Collection -> stream() and parallelStream()
- Array -> Arrays.stream(Object[])
- static factory methods on the stream classes-> Stream.of(Object[]), IntStream.range(int, int) or Stream.iterate(Object, UnaryOperator)
- The lines of a file -> BufferedReader.lines()
- Streams of file paths -> Files;
- Streams of random numbers -> Random.ints();
- Numerous other stream-bearing methods in the JDK, including BitSet.stream(), Pattern.splitAsStream(java.lang.CharSequence), and JarFile.stream().
Operator:
- Intermediate: Stream.filter or Stream.map
- Terminal: Stream.forEach or Stream.reduce.
-
Sequential Collections
Array
-
Mehod in array
- equals(A, B)
- fill(A, x)
- copyOf(A, n)
- copyOfRange(A, s, t)
- toString(A)
- sort(A)
- binarySearch(A, x)
Number Random
Method:
- nextBoolean( )
- nextDouble()
- nextInt()
- nextInt(x)
- setSeed(s)