Found 7442 Articles for Java

Java Program to Capitalize the first character of each word in a String

AmitDiwan
Updated on 31-May-2024 16:49:35

10K+ Views

A string is a class of 'java.lang' package that stores a series of characters. Those characters are actually String-type objects. We must enclose the value of string within double quotes. Generally, we can represent characters in lowercase and uppercase in Java. And, it is also possible to convert lowercase characters into uppercase. This article aims to discuss a Java program to convert the first character of each word into uppercase in a string. Java program to Capitalize the first character of each word in a String Before making a Java program to convert the first lowercase character of a ... Read More

Java Program to Clear the StringBuffer

Shriansh Kumar
Updated on 16-Aug-2024 07:36:08

2K+ Views

On clearing the StringBuffer object, all the characters from the buffer will be removed. In this article, we will write Java program to clear the StringBuffer. StringBuffer is a peer class of String that provides much of the functionality of strings. But, String represents fixed-length, immutable character sequences while StringBuffer represents mutable character sequences. Example Scenario: Input: obj = Java Program Output: res = The result will be an empty StringBuffer object. Using delete() method The StringBuffer class of java.lang package provides a method named delete() to clear the StringBuffer. This method accepts start and end indices ... Read More

Java Program to Create random strings

AmitDiwan
Updated on 29-Mar-2022 12:18:27

746 Views

In this article, we will understand how to create random strings. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”).Below is a demonstration of the same −Suppose our input is −The size of the string is defined as: 10The desired output would be −Random string: ink1n1dodvAlgorithmStep 1 - START Step 2 - Declare an integer namely string_size, a string namely alpha_numeric and an object of StringBuilder namely string_builder. Step 3 - Define the values. Step 4 - Iterate for 10 times usinf a for-loop, generate a random value using the function Math.random() ... Read More

Java program to split a list into two halves

AmitDiwan
Updated on 27-Aug-2024 18:48:06

2K+ Views

In this article, we will understand how to split a list into two halves. A list is an ordered collection that allows us to store and access elements sequentially. It contains index-based methods to insert, update, delete, and search the elements. It can also have duplicate elements. We will be using different approaches to split a list into two halves − Problem Statement Write a Java program to split a list into two halves. As demonstrated below − Input  Input list :[Java, Python, JavaScript, Shell, Scala] Output The first half of the list is: [Java, Python] The second half of ... Read More

Java Program to split into a number of sub-strings

AmitDiwan
Updated on 29-Mar-2022 12:09:04

674 Views

In this article, we will understand how to splitting into a number of sub-strings. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”). A part or a subset of string is called substring.Below is a demonstration of the same −Suppose our input is −Input string: JVMThe desired output would be −The substring list printed as an ArrayList : [J, JV, JVM, V, VM, M] The sub-strings after splitting is: (1) "J" (2) "JV" (3) "JVM" (4) "V" (5) "VM" (6) "M"AlgorithmStep 1 - START Step 2 - Declare a string namely ... Read More

Java program to print even length words

AmitDiwan
Updated on 09-Aug-2024 23:58:12

2K+ Views

In this article, we will understand how to print even-length words. The string is a datatype that contains one or more characters and is enclosed in double quotes (“ ”). Char is a datatype that contains an alphabets an integer or a special character. Problem Statement Write a Java program to print even-length words. Below is a demonstration of the same − Input Input string: Java Programming are cool Output  The words with even lengths are: Java cool Approaches to print even length words Below are the different approaches to print even length words − Using ... Read More

Java Program to Determine the Unicode Code Point at a given index

AmitDiwan
Updated on 29-Mar-2022 11:39:21

424 Views

In this article, we will understand how to determine the unicode code point at a given index. Each character is represented by a unicode code point. A code point is an integer value that uniquely identifies the given character. Unicode characters can be encoded using different encodings, like UTF-8 or UTF-16.Below is a demonstration of the same −Suppose our input is −Input String: Java Program Index value: 5The desired output would be −Unicode Point: 80AlgorithmStep 1 - START Step 2 - Declare a string value namely input_string and two integer values namely index and result Step 3 - Define the ... Read More

Java program to print first letter of each word using regex

AmitDiwan
Updated on 29-Oct-2024 00:38:40

772 Views

In this article, we will understand how to print the first letter of each word using regex. A regular expression is a sequence of characters that forms a search pattern. A regular expression can be a single character or a more complicated pattern. A regular expression helps you match or find other strings or sets of strings, using a specialized syntax held in a pattern. They can be used to search, edit, or manipulate text and data. Problem Statement Write a program in Java to print the first letter of each word using regex. Below is a demonstration of the same ... Read More

Java program to check whether the given string is pangram

AmitDiwan
Updated on 05-Nov-2024 22:03:46

700 Views

In this article, we will understand how to check whether the given string is a pangram in Java. A string is a pangram string if it contains all the characters of the alphabet ignoring the case of the alphabet. Here, we will be using two different approaches: using the main() method and using encapsulation. Problem Statement Given a string write a program in Java to find whether the string is pangram or not. Below is a demonstration of the same − Input  Input string: Abcdefghijklmnopqrstuvwxyz Output Yes, the string is a pangram Different approaches Following are the steps to check whether ... Read More

Java program to swap pair of characters

AmitDiwan
Updated on 09-Aug-2024 23:59:56

2K+ Views

In this article, we’ll learn how to swap pairs of characters in a Java string. We start with a simple method that converts the string into a character array, allowing us to swap characters directly. Then, we’ll explore an object-oriented approach where the swapping logic is encapsulated in a separate method. Both approaches highlight key Java concepts such as string manipulation and method encapsulation. Problem Statement Write a Java program to swap a pair of characters. Below is a demonstration of the same − Input  Input string: Java program Output The string after swapping is: Javg proaram Steps for basic ... Read More

Advertisements