Found 7442 Articles for Java

How to serialize the order of properties using the Jackson library in Java?

Aishwarya Naglot
Updated on 01-Sep-2025 13:33:44

4K+ Views

In this article, let's learn about the serialization of the order of properties using the Jackson library in Java. The Jackson library is used for processing JSON data in Java. The @JsonPropertyOrder is an annotation to be used at the class level. It takes as property a list of fields that defines the order in which fields can appear in the string resulting from the object JSON serialization. The properties included in the annotation declaration can be serialized first(in defined order), followed by any properties not included in the definition. Steps to serialize the order of properties using the Jackson ... Read More

How to delete a string inside a file(.txt) in java?

Aishwarya Naglot
Updated on 01-Sep-2025 13:59:21

7K+ Views

In this article, we will learn how to delete a string inside a file (.txt) in Java. The following are the ways to do so: Using FileOutputStream and replaceAll() method. Using replace() method. Using FileOutputStream The FileOutputStream is a class in the java.io package. It is mainly used for writing data to a file. It creates a file output stream to write data to the specified file. To delete a string inside a file using the FileOutputStream class, follow the steps below: Create a file ... Read More

How can we add an underscore before each capital letter inside a java String?

Maruthi Krishna
Updated on 01-Sep-2025 12:32:35

3K+ Views

In this article, we will learn how to add an underscore before each capital letter in a Java String. We also call this process as "camel case to snake case" conversion. We can solve this problem using the following ways: Using StringBuffer class. Using Regular Expressions. Using StringBuffer class We will use the method called append() of the StringBuffer class to add an underscore. In this method, we will traverse through each character of the string and check if it is an uppercase letter. If it is, we will append ... Read More

How to implement a custom serializer using the Jackson library in Java?

raja
Updated on 06-Jul-2020 11:52:25

1K+ Views

The Jackson API provides a number of methods to work with JSON data. By using Jackson API, we can convert Java objects to JSON string and reform the object from the JSON string. We can implement a custom serializer using the StdSerializer class and need to override the serialize(T value, JsonGenerator gen, SerializerProvider provider) method, the first argument value represents value to serialize(can not be null), the second argument gen represents generator used to output resulting Json content and the third argument provider represents provider that can be used to get serializers for serializing objects value.Syntaxpublic abstract void serialize(T value, JsonGenerator gen, SerializerProvider provider) throws IOExceptionExampleimport java.io.*; ... Read More

How to insert a string in beginning of another string in java?

Maruthi Krishna
Updated on 01-Sep-2025 14:02:49

7K+ Views

Let's learn how to add a string at the beginning of another string in Java. We can do this in the following ways: Using the toCharArray(). Using the String concatenation operator. Using the StringBuilder class. Using the StringBuffer class. Using the toCharArray() toCharArray() method of the String class that helps us to convert a string into a character array. We will use this method to insert a string at the beginning of another string. Following are the steps to do so: Get both strings, suppose we have a string str1 and the string to be added at ... Read More

How convert an array of Strings in a single String in java?

Maruthi Krishna
Updated on 01-Sep-2025 12:34:09

33K+ Views

In this article, we will learn how to convert an array of strings into a single string in Java. There are several ways to do so. The following are the different ways to convert an array of strings into a single string: Using the StringBuffer class. Using the toString() method of the Arrays class. Using the StringJoiner class. Using StringBuffer The StringBuffer class is used for creating mutable (modifiable) strings. It is similar to the String class, but it is mutable. The StringBuffer class is synchronized, which means it is thread-safe. To convert an array of strings into ... Read More

How do we find out if first character of a string is a number in java?

Aishwarya Naglot
Updated on 01-Sep-2025 12:40:40

4K+ Views

In this tutorial, we will learn how to find out if the first character of a String is a digit in Java. Following are the different ways to do so: Using the isDigit() method. Using the regular expressions. Using the charAt() and isDigit() methods. Using the isDigit() method The isDigit() method of the java.lang.Character class accepts a character as a parameter and determines whether it is a digit or not. If the given character is a digit, this method returns true otherwise, this method returns false. Therefore, to determine whether the first character of the given ... Read More

How to read the contents of a webpage into a string in java?

Maruthi Krishna
Updated on 01-Sep-2025 14:11:04

13K+ Views

We can read the contents of a web page in several ways using Java. Here, we are going to discuss three of them. Those are as follows: Using the java.net.URL class. Using the HttpClient library. Using the org.jsoup library. Using the URL class The URL class of the java.net package represents a Uniform Resource Locator which is used to point a resource (file or, directory or a reference) in the world wide web. The openStream() method of this class opens a connection to the URL represented by the current object and returns an InputStream object using which you ... Read More

How to validate given date formats like MM-DD-YYYY using regex in java?

Maruthi Krishna
Updated on 05-Dec-2023 09:18:50

4K+ Views

The java.util.regex package of java provides various classes to find particular patterns in character sequences. The pattern class of this package is a compiled representation of a regular expression. To match a regular expression with a String this class provides two methods namely − compile() − This method accepts a string representing a regular expression and returns an object of the Pattern object. matcher() − This method accepts a String value and creates a matcher object which matches the given String to the pattern represented by the current pattern object. Following is the regular expression to match date in dd-MM-yyyy format − ^(1[0-2]|0[1-9])/(3[01]|[12][0-9]|0[1-9])/[0-9]{4}$ Therefore, to validate ... Read More

How to Convert a String to Hexadecimal and vice versa format in java?

Aishwarya Naglot
Updated on 01-Sep-2025 12:37:22

18K+ Views

In this article, we will learn how to convert a string to hexadecimal and hexadecimal to string in Java. Hexadecimal is a base-16 number system that uses 16 symbols to represent a number. Those symbols can be 0-9 and A-F letters. String to Hexadecimal in Java To convert a string to hexadecimal in Java, we can use the toHexString() method of the Integer class accepts an integer as a parameter and returns a hexadecimal string. Following are the steps to convert a string to hexadecimal: Get the desired String. Create an empty StringBuffer object. Convert it into a ... Read More

Advertisements