Found 4338 Articles for Java 8

How to sort an ArrayList in Ascending Order in Java

AmitDiwan
Updated on 20-Sep-2019 06:52:54

853 Views

To sort an ArrayList in ascending order, the easiest way is to the Collections.sort() method. With this method, you just need to set the ArrayList as the parameter as shown below −Collections.sort(ArrayList)Let us now see an example to sort an ArrayList un ascending order. Here, we are sorting ArrayList with integer elements −Example Live Demoimport java.util.ArrayList; import java.util.Collections; public class Demo {    public static void main(String args[]) {       ArrayList myList = new ArrayList();       myList.add(50);       myList.add(29);       myList.add(35);       myList.add(11);       myList.add(78);       myList.add(64); ... Read More

Differences between wait() and join() methods in Java

Nitin Sharma
Updated on 18-Sep-2019 14:16:47

2K+ Views

In multithreading when we deal with threads there comes the requirement of pause and start a thread for this Threading provides two methods wait and join which are used for the same.The following are the important differences between wait() and join().Sr. No.Keywait()join()1Declarationwait() method is defined in Object class and hence the wait() method is declared in java.lang package.join() method, on the other hand, is also defined in java.lang package but in Thread class.2Usagewait() method is primarily used for the inter-thread communication.On the other hand join() is used for adding sequencing between multiple threads, one thread starts execution after first thread ... Read More

What is the differences between TreeMap, HashMap and LinkedHashMap in Java?

Nitin Sharma
Updated on 18-Sep-2019 14:36:22

1K+ Views

HashSet and ArrayList both are one of the most important classes of the Java Collection framework.The following are the important differences between TreeMap, HashMap and LinkedHashMap.Sr. No.KeyTreeMapHashMapLinkedHashMap1Ordering of elementsThe elements inserted in TreeMap are sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.In case of HashMap it does not guarantees as to the order of the map also it does not guarantee that the order will remain constant over time.LinkedHashMap follows the insertion order of elements and also maintaining an order of elements inserted into ... Read More

What is the differences between HashMap and HashTable in Java

Nitin Sharma
Updated on 18-Sep-2019 14:35:37

755 Views

HashMap and HashTable both are one of the most important classes of Java Collection framework. Both HashMap and HashTable stores the data in key value pair and at the time storing data hashing is used to hash the key and the resulting hash code is used as the index at which the value is stored within the table. But still, there are many differences between both these classes which we would discuss below.The following are the important differences between HashMap and HashTable.Sr. No.KeyHashMapHashTable1IntroductionHashmap is the advanced version of HashTable and is introduced as a new class in JDK 1.2.HashTable on ... Read More

Difference between throw and throws in Java

Nitin Sharma
Updated on 18-Sep-2019 14:29:22

9K+ Views

Both throw and throws are the concepts of exception handing in which throw is used to explicitly throw an exception from a method or any block of code while throws are used in the signature of the method to indicate that this method might throw one of the listed type exceptions.The following are the important differences between throw and throws.Sr. No.Keythrowthrows1DefinitionThrow is a keyword which is used to throw an exception explicitly in the program inside a function or inside a block of code.Throws is a keyword used in the method signature used to declare an exception which might get ... Read More

Difference between Thread.start() and Thread.run() in Java.

Nitin Sharma
Updated on 18-Sep-2019 14:28:24

6K+ Views

As we know that start() and run() are the two important methods of multithreading and one is used to create a new thread while other is used to start executing that thread.Following are the important differences between Thread.start() and Thread.run().Sr. No.Keystart()run()1Implementationstart method of thread class is implemented as when it is called a new Thread is created and code inside run() method is executed in that new Thread.While if run method is executed directly than no new Thread is created and code inside run() will execute on current Thread and no multi-threading will take place.2Definitionstart method is defined in thread ... Read More

Difference between String and Character array in Java.

Nitin Sharma
Updated on 18-Sep-2019 14:27:27

5K+ Views

On technical groud, we can say that both a character array and string contain the sequence of characters and used as a collection of characters. But there are significant differences between both which we would discuss below.The following are the important differences between String and Character array.Sr. No.KeyStringCharacter array1ImplementationString is implemented to store sequence of characters and to be represented as a single data type and single entity.Character Array on the other hand is a sequential collection of data type char where each element is a separate entity.2Internal implementationString internal implementation makes it immutable in nature.Character array is mutable in ... Read More

Difference between Singly linked list and Doubly linked list in Java

Nitin Sharma
Updated on 18-Sep-2019 14:25:53

3K+ Views

Both Singly linked list and Doubly linked list are the implementation of Linked list in which every element of singly-linked list contains some data and a link to the next element, which allows to keep the structure. On the other hand, every node in a doubly-linked list also contains a link to the previous node.The following are the important differences between a Singly linked list and Doubly linked list.Sr. No.KeySingly linked listDoubly linked list1ComplexityIn singly linked list the complexity of insertion and deletion at a known position is O(n)In case od doubly linked list the complexity of insertion and deletion ... Read More

Difference between print() and println() in Java

Nitin Sharma
Updated on 18-Sep-2019 14:23:00

5K+ Views

As we know in Java these both methods are primarily used to display text from code to console. Both these methods are of PrintStream class and are called on static member 'out' of 'System' class which is a final type class.The following are the important differences between print() and println().Sr. No.Keyprint()println()1Implementationprint method is implemented as it prints the text on the console and the cursor remains at the end of the text at the console.On the other hand, println method is implemented as prints the text on the console and the cursor remains at the start of the next line ... Read More

Difference between notify() and notifyAll() in Java

Nitin Sharma
Updated on 02-Mar-2020 10:15:56

6K+ Views

Both notify and notifyAll are the methods of thread class and used to provide notification for the thread.But there are some significant differences between both of these methods which we would discuss below.Following are the important differences between notify and notifyAll.Sr. No.KeynotifynotifyAll1NotificationIn case of multiThreading notify() method sends the notification to only one thread among the multiple waiting threads which are waiting for lock.While notifyAll() methods in the same context sends the notification to all waiting threads instead of single one thread.2Thread identificationAs in case of notify the notification is sent to single thread among the multiple waiting threads so ... Read More

Advertisements