Home »
Java Programs
Java String Programs
This section contains Java String Programs, examples on String Class. Here, you will find programs to get length of the string, convert string into character array, trimming the string, splitting the string, example of startsWith and endsWith methods, replacing the string, reversing the string, example of isEmpty method, Example of String.compareTo method, example of String.subString method, example of String.toLowerCase method, example String.toUpperCase method, example of String.valueOf method, etc.
List of Java String Programs
- Java program to read strings with different methods
In this article, we are going to read string with two different methods StringReader and Scanner class with example, output and explanation.
- How to get length of the string in java?
In this java program, we are going to take string as an input and get the length of the string, to read a string as an input, we are using ‘nextLine()’ method of ‘string’ class.
- How to convert a character array to string in Java?
Learn: How to convert a given character array to string? Here we will take a character array and string object, and then character array will be converted and assigned to the string object.
- How to calculate length of the string using String.length() method in Java?
String.length() method in Java: Here, we will learn how to calculate/get the length of the string using String.length() in Java?
- How to trim a given string using String.trim() method in Java?
String.trim() method in Java: Here, we will learn how to trim a given string using String.trim() method in Java?
- How to spilt string in substrings using String.split() in Java?
String.split() in Java: Here, we will learn how to split string in substrings separating by given delimiter in java?
- Java program to demonstrate example of String.startsWith() and String.endsWith()?
String.startsWith() and String.endsWith() methods of String class: Here, we will learn how to check whether a string starts with a substring or not and whether a string ends with a substring or not?
- How to replace string with another string in java using String.replace() method?
In this program, we will learn how to replace a string with another string using String.replace() method of String class in Java?
- How to reverse a string in Java with and without using StringBuffer.reverse() method?
In this program, there is an example in java where you will learn how to reverse a string with and without using StringBuffer.reverse() method?
- How to check whether a given string is empty or not in Java?
Learn: How to check whether a given string is empty or not using a java program? In this program we will use String.isEmpty() method to check given string is empty or not?
- Java program to convert string to lowercase and uppercase
Here, we will learn how to convert string into Lowercase and Uppercase using String.toLowerCase() and String.toUpperCase() methods in java.
- Java program to get sub string from a given string
Here, we will learn how to get sub string from a given string using String.substring() method in Java? This method returns sub string from given start to end index.
- Java program to convert any type of value to string value using String.valueOf() method
String.valueOf() method - Here, you will learn how to convert any type of value like integer, float, etc to string using String.valueOf(), method which is a built-in method of String class.
- Java program to compare two strings using String.compareTo() method
String.CompareTo() method - Here, you will learn how to compare two strings in java using String.CompareTo() method which is a built-in method of String class.
- Java program to input a string from user and reverse each word of given string
This java program will read a string through input device and reverse each word in given string. Let suppose the input is "Hello Welcome in India" program will print the "olleH emocleW ni aidnI".
- Easiest way to check Given String is Palindrome String or not in Java
This java program will read a string and check whether it is Palindrome or not using easiest method.
- Java program to get string and count number of words in provided string
This java program will read a string and returns the total number of words in an input string; here we are counting the total number of words in a string.
- Java program to check given strings are Anagram or not
This java program will read two strings and check whether they are anagram strings or not.
- Java program to Encrypt/Decrypt String Using AES 128 bits Encryption Algorithm
This java program will read a string and encrypt the input string using AES 128 bits Encryption Algorithm, and also decrypt the Encrypted string using the same method.
- Java program to separate all tokens (words) using StringTokenizer
In this java program, we are going to learn how to access all tokens (words) from a string using StringTokenizer() class?
- Java program to find occurrences of each character in a string
In this java program, we are going to learn how to find occurrences of each character in string? Here, we will read a string and print the total number of count of each character.
- Java program to reverse words of a string
In this java program, we are going to learn how to reverse words of a string? Here, we have a string and print string by changing the order of words.
- Java program to concatenate two strings
In this java program, we are going to learn how to concatenate two strings? Here, we have two strings which will be entered through the user and we will concatenate them.
- Java program to get the last index of any given character in a string
In this java program, we are getting the last index of any given character in a string? Here we are taking a string and character; we are printing its last index in string.
- Java program to make first alphabet capital of each word in a string
Here, we are implementing java program that will read a string and makes first alphabet capital of each word in given string.
- Java program to concatenate two strings without using library function
In this java program, we are going to learn how to concatenate two strings without using library function?
- Lowercase to uppercase conversion without using any library function in Java
Java lowercase to uppercase conversion: Here, we are going to learn how to convert lowercase string to uppercase without using any library function in Java?
- Uppercase to lowercase conversion without using any library function in Java
Java uppercase to lowercase conversion: Here, we are going to learn how to convert uppercase string to lowercase without using any library function in Java?
- Comparing Strings with equals() and compareTo() methods in Java
Here, we are going to learn about the string compare methods – In this tutorial/example, we are comparing strings using equals(), compareTo() and == operator in Java.
- String palindrome program in Java
Checking string palindrome in Java: Here, we are going to learn how to check whether a given string is palindrome string or not?
- String comparison using Collator and String classes in Java
String comparison in Java: Here, we are going to compare two strings using Collator and String Classes in Java.
- String concatenation with primitive data type values in Java
Here, we are going to learn how to concatenate a string with primitive data type values in Java programming language?
- Java program to find occurrences of palindrome words in a string
Here, we are implementing a java program that will read a string and check the palindrome words in string also find the occurrences of words in a given string.
- Java program to swap first and last character of each word in a string
Here, we are implementing a java program that will read a string and we have to swap first and last character of each word in given string.