devxlogo

Java

Image

Understanding Collections.reverse() in Java

A list with a set of values can be reversed using the reverse() method. import java.util.*; public class ReverseACollection{ public static void main(String[] args) { List dataList = new ArrayList();

Image

Using Single Quotes in Java

The difference is visible when you use the single quote with the + sign. The char value is converted to the ascii value and then summed up. However, you have

Image

Using StringJoiner to Join Strings

If you have multiple strings, you can use StringJoiner to join them efficiently. import java.util.StringJoiner;public class UsingStringJoiner{ public static void main(String args[]) { UsingStringJoiner usingStringJoiner = new UsingStringJoiner(); usingStringJoiner.proceed(); }

Image

Using the Java Collections Disjoint Method

See how to use the disjoint method in Collections to find if the given lists are completely disjointed: import java.util.*;public class UsingDisjointInCollections { public static void main(String args[]) { UsingDisjointInCollections

Image

Using Braces Effectively in Java

Although using braces is a a common practice, it is sometimes very misleading and it can take hours to figure out what is wrong. A simple way to avoid such

Image

Understanding the Java.time Package

import java.time.*;import java.time.format.*;class LocaleDate{ public static void main(String args[]) { LocaleDate localeDate = new LocaleDate(); localeDate.proceed(); } private void proceed() { DateTimeFormatter formatter; //Creating an instance to the current time

Image

Validating an URL in Java

Java has some predefined ways of validating an URL. Here is a code snippet: import java.net.*;public class URLValidator{ String validURL = “http://google.com” ; String inValidURL = “httpgoogle.com” ; public static

Image

Getting All Available Time Zones in Java

The package java.time has APIs to get all the available zone ids. The API is getAvailableZoneIds(). import java.time.*;import java.util.*;public class AllTimeZones{ public static void main(String args[]) { AllTimeZones allTimeZones =

Image

Avoid Out of Memory Conditions

Byte[] pdf = toPdf(file); Here, a method creates a PDF file from some input and returns the binary PDF data as a byte array. This code expects that the generated