Java StringJoiner

Java 8 StringJoiner joins strings with delimiter, prefix and suffix. Learn its usage with examples and differences with StringBuilder.

Check if Array Contains an Item in Java

Learn to check if an array contains an element. Also, learn to find the element’s index in the array. 1. Using Arrays Class To check if an element is in an array, we can use Arrays class to convert the array to ArrayList and use the contains() method to check …

Convert long to String in Java

Java example to convert long to String in two different ways using String.valueOf(long l) and Long.toString(long l) methods. Both are static methods.

Convert String to long in Java

Java examples of converting a String to a long type using Long.parseLong(String), Long.valueOf(String) and new Long(String) constructor.

Java Wrapper Classes, Autoboxing and Unboxing

Learn about Java wrapper classes, their usage, conversion between primitives and objects; and autoboxing and unboxing with examples. 1. Java Wrapper Classes In Java, we have 8 primitive data types. Java provides type wrappers, which are classes that encapsulate a primitive type within an Object. A wrapper class wraps (encloses) …

Java group by sort – multiple comparators example

Java examples to do SQL-style group by sort on list of objects. It involves using multiple comparators, each of which is capable of sorting on different field in model object. Table of Contents 1. Model class and multiple comparators 2. Comparator.thenComparing() 3. CompareToBuilder 4. ComparisonChain 5. Chained comparators 1. Model …

Java XPath – Find XML Nodes by Attribute Value

This Java tutorial demonstrates how to get matching nodes for an attribute value in an XML document using XPath. 1. XPath Expressions 1.1. Input XML File First look at the XML file which we will read and then fetch information from it, using xpath queries. 1.2. XPath Expressions Now see …

JAXB @XmlRootElement Annotation Example

Java example of JAXB @XmlRootElement annotation in detail along with its usage during marshalling and unmarshalling operations. 1. @XmlRootElement Annotation The @XmlRootElement maps a class or an enum type to an XML element. When a top-level class or an enum type is annotated with the @XmlRootElement annotation, then its value …

JAXB @XmlElementWrapper Example

Java examples of using JAXB @XmlElementWrapper annotation along with its usage during marshalling and unmarshalling operations.

Jakarta JAXB Annotations (with Example)

Learn about JAXB annotations in detail along with their usage during marshalling and unmarshalling operations eg. @XmlRootElement, @XmlElement and @XmlList,

JAXB Unmarshaller Example

JAXB Unmarshaller interface is responsible for governing the process of deserializing the XML data to Java Objects from variety of input sources.

JAXB Marshaller Example: Converting POJO to XML

The JAXB Marshaller interface is responsible for governing the process of serializing Java content trees i.e. Java objects to XML data. This marshalling from POJO to XML can be done to a variety of output targets. 1. Maven Start with adding the latest ‘jakarta‘ dependencies for adding the JAXB support …

JAXB Schema Validation

Learn to validate XML against schema (xsd) and then unmarshalling XML to Java object. Also learn to check validation errors during xml schema validation if validation fails. Read More: How to generate schema from JAXB classes 1. Convert XML to Java Object after XSD Validation We have already seen the …

Generate XSD from JAXB Java Classes using Eclipse

Learn to create XML schema document (xsd) from JAXB annotated Java classes using Eclipse IDE. 1) Add JAXB Annotations to Java Classes First step is to add annotations such as @XmlRootElement, @XmlAccessorType and @XmlElement etc. to your Java classes. 2) Generate XSD from JAXB Classes 2.1) Navigate to Eclipse Option …

JAXB Read XML to Java Object Example

Java examples to read an XML string or a file into a Java Object (POJO). XML can be supplied by various means such as an XML file, a URL, or a string.

How to Unescape HTML in Java

Java examples unescapes an HTML string to a string containing the actual Unicode characters using StringEscapeUtils and a custom method.

Java Convert Properties File to XML File

Java example to create XML file from Properties object or any existing .properties file. To convert an XML file to .properties file, follow the steps given in linked tutorial. 1. Create XML File from Properties File To convert the properties file into an XML file, the best way is to …

Java Collections sort()

Learn to use Collections.sort() method to sort a list of objects using some examples. By default, the sort() method sorts a given list into ascending order (or natural order). We can use Collections.reverseOrder() method, which returns a Comparator, for reverse sorting. 1. Sorting in Natural Order and Reverse Order 1.1. …

Sorting Arrays in Java

Learn to sort a Java array of primitives, strings and custom objects in multiple ways with the help of Comparable and Comparator interfaces, Arrays.sort() and Stream.sorted() APIs. We will learn to sort arrays in natural ordering, reverse ordering and any other custom ordering as well. 1. Basics of Array Sorting …

How to Create Subarray in Java

Java example to create subarray from array. Learn to use Java 8 Arrays.copyOfRange() method along with converting the subarray to list object.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.