Skip to content

Commit a5ccf70

Browse files
fix collections
1 parent 66d18b9 commit a5ccf70

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ At the beginning, it was the repository with questions from Java interviews. Cur
8181
- [What are the implementations of Map?](collections.md#what-are-the-implementations-of-map)
8282
- [What is the complexity of removing the last element from LinkedList?](collections.md#what-is-the-complexity-of-removing-the-last-element-from-linkedlist)
8383
- [What are the differences between Set and Map?](collections.md#what-are-the-differences-between-set-and-map)
84-
- [Possible maps in concurrency?](collections.md#possible-maps-in-concurrency)
84+
- [What are the possible implementations of Map for concurrency?](collections.md#what-are-the-possible-implementations-of-map-for-concurrency)
8585
- [What is the main difference between Stream API and Collection?](collections.md#what-is-the-main-difference-between-stream-api-and-collection)
8686
- [What should be avoided in parallel stream?](collections.md#what-should-be-avoided-in-parallel-stream)
8787
- [Implement custom version of java.util.stream.Stream with filter/map methods](collections.md#implement-custom-version-of-javautilstreamstream-with-filtermap-methods)
8888
- [What is forEach?](collections.md#what-is-foreach)
8989
- [When is it better to use foreach loop instead of Iterable.forEach()?](collections.md#when-is-it-better-to-use-foreach-loop-instead-of-iterableforeach)
90-
- [SplitIterator?](collections.md#splititerator)
90+
- [What is SplitIterator?](collections.md#what-is-splititerator)
9191

9292
## Concurrency
9393
- [What is usage of wait/notify methods?](#what-is-usage-of-waitnotify-methods)

collections.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
- [What are the implementations of Map?](#what-are-the-implementations-of-map)
99
- [What is the complexity of removing the last element from LinkedList?](#what-is-the-complexity-of-removing-the-last-element-from-linkedlist)
1010
- [What are the differences between Set and Map?](#what-are-the-differences-between-set-and-map)
11-
- [Possible maps in concurrency?](#possible-maps-in-concurrency)
11+
- [What are the possible implementations of Map for concurrency?](#what-are-the-possible-implementations-of-map-for-concurrency)
1212
- [What is the main difference between Stream API and Collection?](#what-is-the-main-difference-between-stream-api-and-collection)
1313
- [What should be avoided in parallel stream?](#what-should-be-avoided-in-parallel-stream)
1414
- [Implement custom version of java.util.stream.Stream with filter/map methods](#implement-custom-version-of-javautilstreamstream-with-filtermap-methods)
1515
- [What is forEach?](#what-is-foreach)
1616
- [When is it better to use foreach loop instead of Iterable.forEach()?](#when-is-it-better-to-use-foreach-loop-instead-of-iterableforeach)
17-
- [SplitIterator?](#splititerator)
17+
- [What is SplitIterator?](#what-is-splititerator)
1818

1919
## What is the complexity for get in Hashmap?
2020
It depends on many things. It's usually O(1), with a decent hash which itself is constant time... but you could have a hash which takes a long time to compute, and if there are multiple items in the hash map which return the same hash code, get will have to iterate over them calling equals on each of them to find a match.
@@ -49,6 +49,7 @@ The other collection interfaces are based on java.util.Map and are not true coll
4949
## What is the difference between LinkedList and ArrayList?
5050
From the hierarchy diagram, they all implement List interface. They are very similar to use. Their main difference is their implementation which causes different performance for different operations. ArrayList is implemented as a resizable array. As more elements are added to ArrayList, its size is increased dynamically. It's elements can be accessed directly by using the get and set methods, since ArrayList is essentially an array. LinkedList is implemented as a double linked list. Its performance on add and remove is better than Arraylist, but worse on get and set methods.
5151
###### Relative links:
52+
+ https://stackoverflow.com/questions/322715/when-to-use-linkedlist-over-arraylist-in-java
5253
+ https://dzone.com/articles/arraylist-vs-linkedlist-vs
5354

5455
## What is better to use LinkedList or ArrayList?
@@ -83,7 +84,7 @@ Main differences between a ***Set*** and a ***Map*** in Java are:
8384
###### Relative links:
8485
+ https://www.quora.com/What-is-the-difference-between-a-Set-and-a-Map-in-Java
8586

86-
## Possible maps in concurrency?
87+
## What are the possible implementations of Map for concurrency?
8788
+ ***ConcurrentHashMap*** allows concurrent modification of the Map from several threads without the need to block them. Collections.synchronizedMap(map) creates a blocking Map which will degrade performance, albeit ensure consistency (if used properly).
8889
+ ***Collections.synchronizedMap(Map)*** is the second option if you need to ensure data consistency, and each thread needs to have an up-to-date view of the map. Use the first if performance is critical, and each thread only inserts data to the map, with reads happening less frequently.
8990
###### Relative links:
@@ -125,7 +126,7 @@ The deficiencies of Iterable.forEach():
125126
###### Relative links:
126127
- https://stackoverflow.com/questions/16635398/java-8-iterable-foreach-vs-foreach-loop
127128

128-
## SplitIterator?
129+
## What is SplitIterator?
129130
###### Relative links:
130131
- https://www.baeldung.com/java-spliterator
131132
- https://www.geeksforgeeks.org/java-util-interface-spliterator-java8/

0 commit comments

Comments
 (0)