Found 9150 Articles for Object Oriented Programming

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

How do we mix two strings and generate another in java?

Maruthi Krishna
Updated on 10-Oct-2019 08:20:46

14K+ Views

Strings are used to store a sequence of characters in Java, they are treated as objects. The String class of the java.lang package represents a String.You can create a String either by using the new keyword (like any other object) or, by assigning value to the literal (like any other primitive datatype).String stringObject = new String("Hello how are you"); String stringLiteral = "Welcome to Tutorialspoint";Concatenating StringsYou can concatenate Strings in Java in the following ways −Using the "+" operator − Java Provides a concatenation operator using this, you can directly add two String literalsExampleimport java.util.Scanner; public class StringExample {   ... Read More

How do we create a string from the contents of a file in java?

Aishwarya Naglot
Updated on 28-Aug-2025 10:30:07

252 Views

We can use the method below to read the contents of a file in Java: Using the java.util.Scanner class. Using the java.io.BufferedReader class. Using the java.nio.file.Files class. Using the Scanner class In Java, you can read the contents of a file in several ways. One way is to read it into a string using the java.util.Scanner class, to do so, follow the steps below: Instantiate the Scanner class, with the path of the file to be read, as a parameter to its constructor. Create an empty String buffer. Start a while loop with a condition, if the ... Read More

How do we split a string on a fixed character sequence in java?

Aishwarya Naglot
Updated on 28-Aug-2025 10:31:48

665 Views

In this article, we will learn how to split a string on a fixed character sequence in Java. We have multiple ways to split a string in Java. Some of them are as follows: Using the split() method of the String class. Using the substring() method of the String class. Using the StringTokenizer class. Let's discuss each of them in detail one by one. Using the split() method of the String class The split() method of the String class accepts a delimiter (in the form of a string), divides the current String into smaller strings based on the ... Read More

Explain about StringJoiner in java8?

Maruthi Krishna
Updated on 10-Oct-2019 07:05:21

169 Views

Since Java8 StringJoiner class is introduced this you can construct a sequence of characters separated by desired delimiter.Sr.NoConstructor & Description1StringJoiner(CharSequence delimiter)This constructor creates an empty (no characters) StringJoiner, just with a copy of the specified delimiter.2StringJoiner(CharSequence delimiter, CharSequence prefix, CharSequence suffix)This constructs a StringJoiner without characters.Methods of StringJoiner classadd() − This method accepts a CharacterSequence object (Segment, String, StringBuffer, StringBuilder) and adds it to the current Joiner separating the next and previous elements (if any) with delimiter at the time of constructing it.Exampleimport java.util.StringJoiner; public class StringJoinerExample {    public static void main(String args[]) {       StringJoiner joiner ... Read More

How to find a unique character in a string using java?

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

17K+ Views

In this article, we will learn how to find a unique character in a string in Java. A unique character is a character that occurs only once in the string, while all others can occur multiple times. We can solve this problem using the following ways: Using Brute Force method. Using HashMap. Using brute force method To find a unique character in a given string, we will use a brute force approach. In the brute force approach, we will use two loops to compare each character to the rest of the string. Let's look at the steps: ... Read More

How do we extract all the words start with a vowel and length equal to n in java?

Aishwarya Naglot
Updated on 28-Aug-2025 09:38:37

2K+ Views

In this article, we will learn to extract all the words that start with a vowel and have a length equal to n from a given text file or string in Java. We can solve this problem using the following ways: Using the split() method of the String class. Using the StringTokenizer class. Using Regular Expressions. Using the split() method of the String class To extract all the words that start with a vowel and have a length equal to n from a given text file or string in Java, we can use the following steps: The ... Read More

Advertisements