Maruthi Krishna has Published 951 Articles

What is the easiest way to reverse a String in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Dec-2023 09:29:13

916 Views

Built-in reverse() method The StringBuffer class provides you a method named reverse(). It reverses the contents of the current StringBuffer object and returns the resultant StringBuffer object. It is the easiest way to reverse a Sting using Java. To do so − Instantiate the StringBuffer class by passing the required String as ... Read More

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

Maruthi Krishna

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 ... Read More

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

Maruthi Krishna

Maruthi Krishna

Updated on 04-Dec-2023 11:35:02

2K+ Views

Using the StringBuffer class To add underscore before each capital letter in a String using StringBuffer − Create an empty StringBuffer object. The isUpperCase() method of Character class accepts a character and verifies whether it is in upper case, if so, this method returns true. Using this method, verify each character in the ... Read More

Can I import same package twice? Will JVM load the package twice at runtime?

Maruthi Krishna

Maruthi Krishna

Updated on 23-Nov-2023 10:04:58

1K+ Views

In Java classes and interfaces related to each other are grouped under a package. Package is nothing but a directory storing classes and interfaces of a particular concept. For example, all the classes and interfaces related to input and output operations are stored in java.io package. Creating a Package You can group ... Read More

Can we declare an interface with in another interface in java?

Maruthi Krishna

Maruthi Krishna

Updated on 22-Nov-2023 12:56:18

901 Views

An interface in Java is a specification of method prototypes. Whenever you need to guide the programmer or, make a contract specifying how the methods and fields of a type should be you can define an interface. To create an object of this type you need to implement this interface, provide ... Read More

How to create date object in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 14-Sep-2023 02:38:59

28K+ Views

Using the Date classYou can create a Date object using the Date() constructor of java.util.Date constructor as shown in the following example. The object created using this constructor represents the current time.ExampleLive Demoimport java.util.Date; public class CreateDate {    public static void main(String args[]) {             ... Read More

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

Maruthi Krishna

Maruthi Krishna

Updated on 14-Sep-2023 02:33:17

29K+ Views

Using StringBufferCreate an empty String Buffer object.Traverse through the elements of the String array using loop.In the loop, append each element of the array to the StringBuffer object using the append() method.Finally convert the StringBuffer object to string using the toString() method.Examplepublic class ArrayOfStrings {    public static void main(String ... Read More

How to get list of all files/folders from a folder in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 12-Sep-2023 03:22:52

36K+ Views

The class named File of the java.io package represents a file or directory (path names) in the system. This class provides various methods to perform various operations on files/directories.To get the list of all the existing files in a directory this class provides the files class provides list() (returns names) ... Read More

How to get the current date in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Sep-2023 21:38:15

37K+ Views

You can get the current date in Java in various ways. Following are some of them −The constructor of Date classThe no-arg constructor of the java.util.Date class returns the Date object representing the current date and time, using this you can print the current date as shown below −ExampleLive Demoimport java.text.SimpleDateFormat; ... Read More

How to convert Java object to JSON using Jackson library?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Sep-2023 11:49:04

45K+ Views

JSON or JavaScript Object Notation is a lightweight text-based open standard designed for human-readable data interchange. Conventions used by JSON are known to programmers, which include C, C++, Java, Python, Perl, etc.There are several Java libraries available to handle JSON objects. Jackson is a simple java based library to serialize ... Read More

Advertisements