Sort Items in the Collection
Use Collections from java.util to sort our list. Let’s have a look at the sample below: The result:
Use Collections from java.util to sort our list. Let’s have a look at the sample below: The result:
String is an immutable data type (does not allow modification data after instantiation) while StringBuilder and StringBuffer are mutable data types. The table below will list the different characteristics between StringBuffer and StringBuilder. No. StringBuffer StringBuilder 1. Mechanism StringBuffer is synchronized (thread-safe). It means two threads can’t execute simultaneously methods of StringBuffer. StringBuilder is non-synchronized (not thread-safe). It […]
List and Set are common collections in Java. They are used to contain items that have the same data type. The difference is List allow contain duplication of items while Set is not allowed. Code example: Result: NOTEs Errors: 1. Exception in thread “main” java.lang.UnsupportedOperationException: remove Run the following code below to get the error: […]
Set is a collection that contains unique items. In this post, we will cover the way to convert a string array to Set<String>. There are 2 approaches to do this requirement. Let’s consider which one we need to use. 1) Using new HashSet<>() HashSet is a mutable collection. That means we can modify the set […]
We have 2 main books to learn Java SE 11. One for theory and one for practice. There 2 books also used to prepare for your examination with code: 1Z0-819 Disclaimer: these 2 books are the intellectual property of Scott and Jeanne authors, and are being sold on the Amazon website. I share them with […]