Found 4338 Articles for Java 8

Making a Java String All Uppercase or All Lowercase.

Ankitha Reddy
Updated on 30-Jul-2019 22:30:21

901 Views

The toUpperCase() method converts all of the characters in this String to upper case using the rules of the default locale The toLowerCase() method converts all of the characters in this String to lower case using the rules of the default locale. Example Live Demo import java.lang.*; public class StringDemo { public static void main(String[] args) { // converts all upper case letters in to lower case letters String str1 = "SELF LEARNING CENTER"; System.out.println("string value = ... Read More

Java program to convert a string to lowercase and uppercase.

Srinivas Gorla
Updated on 18-Jun-2020 08:12:46

847 Views

ExampleLive Demoimport java.lang.*; public class StringDemo {    public static void main(String[] args) {         // converts all upper case letters in to lower case letters       String str1 = "SELF LEARNING CENTER";       System.out.println("string value = " + str1.toLowerCase());       str1 = "TUTORIALS POINT";           System.out.println("string value = " + str1.toLowerCase());       // converts all lower case letters in to upper case letters       String str2 = "This is TutorialsPoint";       System.out.println("string value = " + str2.toUpperCase());       str2 = "www.tutorialspoint.com";       System.out.println("string value = " + str2.toUpperCase());          }   } Outputstring value = self learning center string value = tutorials point string value = THIS IS TUTORIALSPOINT string value = WWW.TUTORIALSPOINT.COM

Converting to upper case in Java.

Ramu Prasad
Updated on 26-Feb-2020 09:41:12

180 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

How to Split a String with Escaped Delimiters?

Sravani S
Updated on 26-Feb-2020 09:42:44

286 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

How to Split String in Java using Regular Expression?

V Jyothi
Updated on 26-Feb-2020 08:27:11

4K+ Views

The split(String regex) method of the String class splits 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.ExampleLive Demoimport java.lang.*; public class StringDemo {    public static void main(String[] args) {       String str = "a d, m, i.n";       String delimiters = "\s+|, \s*|\.\s*";       // analysing the string       String[] tokensVal = str.split(delimiters); ... Read More

Java StringTokenizer and String Split Example.

Priya Pallavi
Updated on 26-Feb-2020 08:26:10

884 Views

The StringTokenizer class allows an application to break a string into tokens.This class is a legacy class that is retained for compatibility reasons although its use is discouraged in new code.ExampleLive Demoimport java.util.*; public class Sample {    public static void main(String[] args) {       // creating string tokenizer       StringTokenizer st = new StringTokenizer("Come to learn");       // counting tokens       System.out.println("Total tokens : " + st.countTokens());       // checking tokens       while (st.hasMoreTokens()) {          System.out.println("Next token : " + st.nextToken());   ... Read More

What is the correct way to check if String is empty in Java?

Jai Janardhan
Updated on 26-Feb-2020 09:43:28

107 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

What is the difference between replace() and replaceAll() in Java?

Govinda Sai
Updated on 26-Feb-2020 10:04:59

1K+ 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

Checking for Null or Empty in Java.

George John
Updated on 30-Jul-2019 22:30:21

12K+ Views

We can check whether a particular String is empty or not, using isBlank() method of the StringUtils class. This method accepts an integer as a parameter and returns true if the given string is empty, or false if it is not. Example Live Demo import org.apache.commons.lang3.StringUtils; public class Sample { public static void main(String args[]) { String str = ""; Boolean bool = StringUtils.isBlank(str); System.out.println(bool); } } Output true

How to replace characters on String in Java?

Ramu Prasad
Updated on 30-Jul-2019 22:30:21

218 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

Advertisements