Right Pad a String with Spaces or Zeros
Java examples to right pad a string with spaces or zeros to make it fixed length using the StringUtils, Strings classes and custom solution.
Java examples to right pad a string with spaces or zeros to make it fixed length using the StringUtils, Strings classes and custom solution.
Java examples to left pad a string with spaces, zeros or any other pad character using the StringUtils, Strings classes and custom solution.
Java 8 StringJoiner joins strings with delimiter, prefix and suffix. Learn its usage with examples and differences with StringBuilder.
Learn to remove extra white spaces between words in a String in Java. Do not forget to check if string has leading or trailing spaces. Trim such Strings.
Learn how to trim leading and/or trailing whitespaces from a Java String using regular expressions and a new String.strip() API in Java 11.
Learn to reverse all the characters of a Java string using the recursion and StringBuilder.reverse() methods.
Learn to reverse each word in a sentence in Java with example. We will reverse words in string using StringBuilder and StringUtils classes.
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 …
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.
Java examples of converting a String to a long type using Long.parseLong(String), Long.valueOf(String) and new Long(String) constructor.
In Java, converting an int value to String is not difficult, but knowing which method may save us a few CPU cycles is worth knowing.
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) …
Learn to convert a String to title case using the WordUtils class and create a custom solution by splitting and capitalizing each word.
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 …
Learn to use Hibernate validator CDI module to inject default bean validation factory implementation i.e. ValidatorFactory and Validator.
Learn to solve java exception UnexpectedTypeException
while using hibernate validator for java bean validations.
Hibernate validator example to validate the Java beans using Jakarta bean validation API. Learn to configure messages and interpolation.
Learned default spring security login form and auto-configuration and configuring custom login form, success and failure URLs and handlers.
Java configuration example to enable spring security with the help of @EnableWebSecurity annotation and WebSecurityConfigurerAdapter class.
Java xpath check if node exists or check if attribute exists in Java with example by execute an xpath expression to count the matching nodes.
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 …
Java example of unmarshaling a bean without jaxb annotations. Learn to unmarshal java objects with missing @XmlRootElement.
JAXB marshal without @XmlRootElement to fix errors like unable to marshal type T as an element because it is missing an @XmlRootElement annotation.
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 …
Java examples of using JAXB @XmlElementWrapper annotation along with its usage during marshalling and unmarshalling operations.
Learn about JAXB annotations in detail along with their usage during marshalling and unmarshalling operations eg. @XmlRootElement, @XmlElement and @XmlList,
JAXB Unmarshaller interface is responsible for governing the process of deserializing the XML data to Java Objects from variety of input sources.
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 …
This JAXB tutorial demonstrates using MOXy to convert JSON to Java Object. The JSON can be read from a File or a String as an input source.
This Java tutorial uses JAXB and MOXy to marshal Java objects to JSON string or write JSON to file using simple examples.
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 …
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 …
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.
Java examples to read an XML file and print XML string to console or write XML to file using StringWriter and FileOutputStream objects.
In this Java example, learn to convert XML string to XML Document and also convert XML file content to XML Document with examples.
Java examples unescapes an HTML string to a string containing the actual Unicode characters using StringEscapeUtils and a custom method.
Java examples to escape HTML using the StringEscapeUtils.escapeHtml4(), Spring’s HtmlUtils.htmlEscape() and custom logic for special cases.
Java example to create properties file from a given XML file. This code can be used to read properties key-values from 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 …
Learn to parse and read XML files using Java StAX parser. StAX (Streaming API for XML) provides two ways to parse XML: Cursor-based and Iterator-based APIs.
Learn to create clone of array in Java. The clone() default creates a shallow copy of an array. Use SerializationUtils.clone() for deep copy.
Learn to sort a string alphabetically using Stream.sort(), Arrays.sort() and custom sort() method using simple arrays and swapping example.
Java 8 example of sorting a collection of objects on multiple fields (ORDER BY sort) using Comparator thenComparing() method.
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. …
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 …
Java examples to convert a string into string array using String.split() and java.util.regex.Pattern.slipt() methods.
Java example to create subarray from array. Learn to use Java 8 Arrays.copyOfRange() method along with converting the subarray to list object.
Java examples to use DateTimeFormatter for formatting ZonedDateTime, LocalDateTime, LocalDate and LocalTime with inbuilt and custom patterns.
Java 8 examples to convert from LocalDate to java.sql.Date and vice versa.
Java examples to convert from LocalTime to java.sql.Time and vice versa.
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.