devxlogo

Java

Palindrome Validation Using Java

We are well aware of validating a Palindrome string. The emphasize here is usage of StringBuffer/Builder and the reverse method to get the string reversed instead of using an interactive

How to Use Scanner to Receive Command Line Input

Scanner is a simple and easy-to-use utility provided by Java. import java.util.Scanner;public class ScannerDemo{ public static void main(String args[]) { Scanner scanner = new Scanner(System.in); //Initializing the Scanner with the

Using valueOf() Instead of toString()

The valueOf() method is useful when you do not know the value contained and it might throw a NullPointerException. It returns null and you can handle the same in your code

Java Collections Performance, MAP

Improve Java performance with MAP. Add Contains keys Next Data StructureHashMap O(1) O(1) O(h/n) Hash TableEnumMap O(1) O(1) O(1) ArrayLinkedHashMap O(1) O(1) O(1) Hash Table+Linked ListTreeMap O(log n) O(log n)

New Way to Iterate a List in Java 8

We can see that the method println is referred by System.out using :: import java.util.*;public class NewForEach { public static void main(String args[]) { List empNames = new ArrayList(); empNames.add(“Andrew”);

Java Collections Performance, SET

Java collections – performance (Time Complexity) A set is a collection that contains no duplicate elements. Add Next Contains Data StructureHashSet O(1) O(h/n) O(1) Hash TableEnumSet O(1) O(1) O(1) Bit

Making a File Read-only Using Java

Files have multiple properties and they are interesting to use. In fact, your own file system can be developed using them. Create a file named PATH.txt and try this program

Java Collections Performance, LISTS

Java collections – performance (Time Complexity) A list is an ordered collection of elements. Add Remove Get Contains Data StructureArrayList O(1) O(n) O(1) O(n) ArrayCopyonWriteArrayList O(n) O(n) O(1) O(n) ArrayLinkedList