Skip to content

Tag Archives: Java-String-Programs

Write a function that takes a String as an argument and prints all unique words in it. Examples: Input : Java is great. Grails is… Read More
Given a string, extract words from it. “Words” are defined as contiguous strings of alphabetic characters i.e. any upper or lower case characters a-z or… Read More
In the article Check if a given string is a valid number, we have discussed general approach to check whether a string is a valid… Read More
Given a string, count the total number of vowels (a, e, i, o, u) in it. There are two methods to count total number of… Read More
Given a string of digits, remove leading zeros from it. Examples: Input : 00000123569 Output : 123569 Input : 000012356090 Output : 12356090 Recommended: Please… Read More
Prerequisite: StringJoiner StringJoiner is very useful, when you need to join Strings in a Stream. Task : Suppose we want the string “[George:Sally:Fred]”, where we… Read More
Given a string, remove all the leading and trailing spaces from the string and return it. Examples: Input : str = " Hello World "… Read More
This article discusses 5 different ways to reverse a string in Java with examples. Examples:     Recommended: Please try your approach on {IDE} first, before moving… Read More
Searching a character in the String indexOf(char c) : It searches the index of specified character within a given string. It starts searching from beginning… Read More
Strings are immutable:  Strings are immutable in Java and therefore if a password is stored as plain text it will be available in memory until Garbage collector… Read More
Given two string variables a and b, swap these variables without using temporary or third variable in Java. Use of library methods is allowed. Examples:… Read More
Initializing Strings in Java 1. Direct Initialization(String Constant) : In this method, a String constant object will be created in String pooled area which is… Read More
Try to figure out the output of this code: public class Test {     public static void main(String[] args)     {         System.out.println(45+5 + "=" +45+5);     } }… Read More
Splitting a string by some delimiter is a very common task. For example, we have a comma-separated list of items from a file and we… Read More
Given a set of characters and a positive integer k, print all possible strings of length k that can be formed from the given set.… Read More