Please enable JavaScript.
Coggle requires JavaScript to display documents.
Java General Q&A (What is the difference between ArrayList and…
Java General Q&A
-
-
-
-
What is the difference between a HashSet, a TreeSet and a LinkedHashSet ?
The HashSet is backed by a hash table and the elements are not ordered. It offers O(1) for add(), remove() and contains()
Elements in the TreeSet are sorted in ascending order by default. However add(), remove() and contains() require O(log n)
It is generally faster to add elements to a HashSet and then convert the collection to a TreeSet for a duplicate-free sorted traversal.
A LinkedHashSet allows an iteration in the order in which the elements were inserted. Requires more memory than a HashSet but otherwise O(1) for the basic operations
What is a Constructor, Constructor Overloading in Java and Copy-Constructor?
The constructor is a function that is called upon using the "new" keyword to create an instance of some class. It is used to initialize the class and provide it with all necessary data.
Constructor overloading is the same concept as function overloading but regarding the constructor of a class.
Java supports copy constructors like C++, but unlike C++ Java doesn’t create a default copy constructor.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
What is a deadlock?
A situation in which two threads wait on each other to release a lock. Since the one thread waits on the other and vice versa the execution stalls indefinetely.
-
What is an iterator?
An iterator is an interface that allows iterating over any collection. Every collection has an iterator. As oppossed to iterating via a standard for-loop, using an iterator allows deleting elements from a collection.
-
-
-
-
-
-
-
-
-
-
-