String in Java are the objects which can store characters of values in Java, it act the same as an array of characters in Java. Java String is one of the most important topics in Java programming. It is widely used to manipulate and process textual data. In this article, we will learn about Java String with some Java Practice Problems.
Take a look at our Java String Exercise, which will cover the Practice Problems in Java with a series of Java String exercise questions that will help you practice and reinforce your knowledge of String manipulation in Java. These practice problems are both beginner-friendly and experienced-friendly. So, let's dive into the world of Java String exercises and enhance your programming abilities!
Beginner Questions
Ready to test your Java string skills? This section offers beginner-friendly exercises. Practice creating, modifying, and working with strings to build a solid foundation for your Java programming journey.

1. Java String Program to Print Even-Length Words
Input: s = "This is a java language"
Output: This is java language
Explanation: All the elements with the length even are printed.
"This" length is 4 so printed whereas "a" length is 1 so not Printed.
2. Java String Program to Insert a String into Another String
Input: originalString = "GeeksGeeks",
stringToBeInserted = "For",
index = 4
Output: "GeeksForGeeks"
Explanation: Adding the new String to orignal String at the index given.
3. Java String program to check whether a string is a Palindrome
Input: str = “geeks”
Output: No
Explanation: Palindrome is String which can be read same both forth and reverse side or can be said String whose orignal string is same as reverse of String.
"AbbA" , "DaD" , etc these are some examples of Palindrom String.
4. Java String Program to Check Anagram
Input: str1 = "Listen"
str2 = "Silent"
Output: Yes
Explanation: A string is called Anagram of other string when the it contains the same characters, only the order of characters can be different.
Example Listen -> E:1 , I:1 , L: 1 , N:1 , S:1 , T:1
Silent -> E:1 , I:1 , L: 1 , N:1 , S:1 , T:1
As the occurence of elements are same in both the String hence they are anagram of each other.
5. Java String Program to Reverse a String
Input: "Geeks"
Output: skeeG
6. Java String Program to Swapping Pair of Characters
Input: str = “GeeksForGeeks”
Output: eGkeFsroeGkes
Explanation: Swap Pair of Characters
Pairs to Swap: {G e} , {e k} , { s F } , { o r } , { G e } , { e k } , { s }
After Swap: { e G } , { k e } , { F s } , { r o } , { e G } , { k e } , { s }
Result: " eGkeFsroeGkes "
7. Java String Program to Replace a Character at a Specific Index
Input: str = "Geeks for geeks" , index = 10 , ch = 'G'
Output: "Geeks for Geeks"
Explanation: String str is "Geeks for geeks" , as we can see index 10 refers to "Geeks for geeks" this element . So , we will replace it with 'G'.
Result becomes "Geeks for Geeks"
8. Java String Program to Remove Leading Zeros
Input: 000012356098
Output: 12356098
Explanation: Removing all the elements from the beginning of String which doesn't add any value to the number.
9. Java String Program to Sort a String
Input : "software"
Output : "aeforstw"
10. Java String Program to Compare Two Strings
Input: str1 = "geeks"
str2 = "Geeks"
Output: False
Explanation: As 'g' is not equal to 'G' so we can't consider them equal.
Advanced DSA Level Problems
This section unleashes advanced DSA-level string problems. Tackle patterns, searches, and transformations to become a Java string pro.
11. Program to Find the Sum of Two Large Numbers.
Input : str1 = "7777555511111111",
str2 = "3332222221111"
Output : 7780887733332222
12. Program to Extract Substring from a String with Equal 0, 1, and 2.
Input: str = “102100211”
Output: 5
Explanation: "102" , "021" , "210" , " 021" , "210021" these are combinations can be formed where the occurrence of 0 , 1 and 2 all are equal.
13. Program to Add Binary Strings
Input : str1 = "1001"
str2 = "11"
Output : "1100"
Explanation : "1001" represents for 9 and "11" represents for 3 then result should be 12 which means result = "1100".
14. Program to Validate an IP address
Input : "125.512.100.1"
Output : Valid
15. Program to Print all Permutations of a String in Java
Input : abc
Output : abc , acb , bac , bca , cab , cba
Explanation: All the sequence can be formed using these the string will be printed.
More Java Practice Exercises
Conclusion
Once you have completed the Java String Exercises! Now you can handle strings like a pro. Feeling confident? Don’t stop practicing! Play around with these exercises again and try your own ideas to become a Java string master in no time.
Similar Reads
Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Java s
10 min read
Java Interview Questions and Answers Java is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per
15+ min read
Java OOP(Object Oriented Programming) Concepts Java Object-Oriented Programming (OOPs) is a fundamental concept in Java that every developer must understand. It allows developers to structure code using classes and objects, making it more modular, reusable, and scalable.The core idea of OOPs is to bind data and the functions that operate on it,
13 min read
SQL Commands | DDL, DQL, DML, DCL and TCL Commands SQL commands are crucial for managing databases effectively. These commands are divided into categories such as Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Data Query Language (DQL), and Transaction Control Language (TCL). In this article, we will e
7 min read
Arrays in Java Arrays in Java are one of the most fundamental data structures that allow us to store multiple values of the same type in a single variable. They are useful for storing and managing collections of data. Arrays in Java are objects, which makes them work differently from arrays in C/C++ in terms of me
15+ min read
TCP/IP Model The TCP/IP model (Transmission Control Protocol/Internet Protocol) is a four-layer networking framework that enables reliable communication between devices over interconnected networks. It provides a standardized set of protocols for transmitting data across interconnected networks, ensuring efficie
7 min read
Inheritance in Java Java Inheritance is a fundamental concept in OOP(Object-Oriented Programming). It is the mechanism in Java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, Inheritance means creating new classes based on existing ones. A class that inherits from an
13 min read
Collections in Java Any group of individual objects that are represented as a single unit is known as a Java Collection of Objects. In Java, a separate framework named the "Collection Framework" has been defined in JDK 1.2 which holds all the Java Collection Classes and Interface in it. In Java, the Collection interfac
15+ min read
Java Exception Handling Exception handling in Java allows developers to manage runtime errors effectively by using mechanisms like try-catch block, finally block, throwing Exceptions, Custom Exception handling, etc. An Exception is an unwanted or unexpected event that occurs during the execution of a program, i.e., at runt
10 min read
Basics of Computer Networking A computer network is a collection of interconnected devices that share resources and information. These devices can include computers, servers, printers, and other hardware. Networks allow for the efficient exchange of data, enabling various applications such as email, file sharing, and internet br
14 min read