
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7442 Articles for Java

1K+ Views
In Java, converting a string to lowercase or uppercase is a common operation used in text processing, formatting, and case normalization. The String class provides built-in methods to achieve this with ease. This article explores how to use these methods with practical examples, demonstrating step-by-step how to convert strings between uppercase and lowercase. Key Methods toLowerCase(): Converts all characters in a string to lowercase. toUpperCase(): Converts all characters in a string to uppercase. These methods are part of the java.lang.String class and work seamlessly for any string input. Using toLowerCase() ... Read More

271 Views
This method has two variants. The first variant converts all of the characters in this String to upper case using the rules of the given Locale. This is equivalent to calling toUpperCase(Locale.getDefault()).The second variant takes a locale as an argument to be used while converting into upper case.ExampleLive Demoimport java.io.*; public class Test { public static void main(String args[]) { String Str = new String("Welcome to Tutorialspoint.com"); System.out.print("Return Value :"); System.out.println(Str.toUpperCase()); } }OutputReturn Value :WELCOME TO TUTORIALSPOINT.COM

444 Views
The split(String regex) method of the String class splits this string around matches of the given regular expression.ExampleLive Demopublic class Sample{ public static void main(String args[]){ String s = "|A|BB||CCC|||"; String[] words = s.split("\|"); for (String string : words) { System.out.println(string); } } }OutputA BB CCC

6K+ Views
In this article, we will learn to split a string in Java using regular expressions. We will be using the split(String regex) method of the String class to split this string around matches of the given regular expression. This method works in the same way as invoking the method i.e. split(String regex, int limit) with the given expression and a limit argument of zero. Therefore, trailing empty strings are not included in the resulting array. Steps to split string in Java using regular expression Following are the steps to split strings in Java using regular expression − ... Read More

2K+ Views
Both StringTokenizer class and the split() method in Java are used to divide a string into tokens or substrings. However, they are different from each other. The StringTokenizer class does not support regular expressions, whereas the split() method works with regular expressions. In this article, we will see some Java examples that show how to split strings using them. Example Scenario: Input: str = "simple easy learning" Output: split_str = "simple", "easy", "learning" Splitting String using StringTokenizer Class The StringTokenizer is a legacy class of java.util package. This class provides methods to break a string into multiple tokens. It ... Read More

180 Views
We can verify whether the given string is empty using the isEmpty() method of the String class. This method returns true only if length() is 0.ExampleLive Demoimport java.lang.*; public class StringDemo { public static void main(String[] args) { String str = "tutorialspoint"; // prints length of string System.out.println("length of string = " + str.length()); // checks if the string is empty or not System.out.println("is this string empty? = " + str.isEmpty()); } }Outputlength of string = 14 is this string empty? = false

2K+ Views
The replace method of the String class accepts two characters and it replaces all the occurrences of oldChar in this string with newChar.Exampleimport java.io.*; public class Test { public static void main(String args[]) { String Str = new String("Welcome to Tutorialspoint.com"); System.out.print("Return Value :" ); System.out.println(Str.replace('o', 'T')); System.out.print("Return Value :" ); System.out.println(Str.replace('l', 'D')); } }OutputReturn Value :WelcTme tT TutTrialspTint.cTm Return Value :WeDcome to TutoriaDspoint.comThe replaceAll() method replaces each substring of this string that matches the given regular expression with the given replacement.Exampleimport java.io.*; ... Read More

13K+ Views
A string is a collection of characters. In Java, it is represented by the String class, and it accepts NULL values. Checking for Null or Empty in Java In this article, we will learn if a string is null or empty in Java. The following are the ways to check if a string is null or empty in Java: Using isEmpty() Method Using length() Method Using isBlank() Method Using isEmpty() Method The isEmpty() method of the String class checks if a string is empty. It returns TRUE if ... Read More

329 Views
The replace method of the String class accepts two characters and it replaces all the occurrences of oldChar in this string with newChar.Example Live Demoimport java.io.*; public class Test { public static void main(String args[]) { String Str = new String("Welcome to Tutorialspoint.com"); System.out.print("Return Value :" ); System.out.println(Str.replace('o', 'T')); System.out.print("Return Value :" ); System.out.println(Str.replace('l', 'D')); } }OutputReturn Value :WelcTme tT TutTrialspTint.cTm Return Value :WeDcome to TutoriaDspoint.com

315 Views
The isEmpty() method of the String class returns true if the length of the current string is 0.ExampleLive Demoimport java.lang.*; public class StringDemo { public static void main(String[] args) { String str = "tutorialspoint"; //prints length of string System.out.println("length of string = " + str.length()); //checks if the string is empty or not System.out.println("is this string empty? = " + str.isEmpty()); } }Outputlength of string = 14 is this string empty? = false