A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/java/character-iswhitespace-method-in-java-with-examples/ below:

Character.isWhitespace() method in Java with examples

Character.isWhitespace() method in Java with examples

Last Updated : 06 Dec, 2018

The

java.lang.Character.isWhitespace()

is an inbuilt method in a java that determines if the specified character (Unicode code point) is white space according to Java. A character is a Java whitespace character if and only if it satisfies one of the following criteria:

Syntax:
public static boolean isWhitespace(datatype character)
Parameters

: The function accepts one mandatory parameter

character

. This parameter can be of datatype int or char. It specifies the character to be tested.

Return value:

This method returns true if the character is a Java whitespace character, false otherwise. Below programs illustrate the Character.isWhitespace(char ch) method:

Program 1: Java
// Java program to illustrate the Character.isWhitespace()
// method when the passed parameter is a character
import java.lang.*;

public class gfg {

    public static void main(String[] args)
    {

        // create 2 char primitives c1, c2
        char c1 = '*', c2 = '\f';

        boolean b1 = Character.isWhitespace(c1);
        boolean b2 = Character.isWhitespace(c2);

        String str1 = "c1 is a Java whitespace character is " + b1;
        String str2 = "c2 is a Java whitespace character is " + b2;

        // print b1, b2 values
        System.out.println(str1);
        System.out.println(str2);
    }
}
Output

:

c1 is a Java whitespace character is false
c2 is a Java whitespace character is true
Program 2: Java
// Java program to demonstrate the Character.isWhitespace()
// method when the passed parameter is a character
import java.lang.*;

public class gfg {

    public static void main(String[] args)
    {

        // create 2 char primitives c1, c2
        char c1 = '/', c2 = '\f';

        boolean b1 = Character.isWhitespace(c1);
        boolean b2 = Character.isWhitespace(c2);

        String str1 = "c1 is a Java whitespace character is " + b1;
        String str2 = "c2 is a Java whitespace character is " + b2;

        // print b1, b2 values
        System.out.println(str1);
        System.out.println(str2);
    }
}
Output

:

c1 is a Java whitespace character is false
c2 is a Java whitespace character is true
Program 3:

When the parameter is of type

int

.

Java
// Java program to demonstrate the
// Character.isWhitespace()
// method when the passed parameter
// is a character
import java.lang.*;

public class gfg {

    public static void main(String[] args)
    {

        // create 2 int primitives c1, c2
        int c1 = 0x451c, c2 = 0x4abc;

        boolean b1 = Character.isWhitespace(c1);
        boolean b2 = Character.isWhitespace(c2);

        String str1 = "c1 represents Java whitespace character is " + b1;
        String str2 = "c2 represents Java whitespace character is " + b2;

        // print b1, b2 values
        System.out.println(str1);
        System.out.println(str2);
    }
}
Output

:

c1 represents Java whitespace character is false
c2 represents Java whitespace character is false
Program 4:

When the parameter is of type

int

.

Java
// Java program to demonstrate the Character.isWhitespace()
// method when the passed parameter is a character
import java.lang.*;

public class gfg {

    public static void main(String[] args)
    {

        // create 2 int primitives c1, c2
        int c1 = 0x001c, c2 = 0x1bbc;

        boolean b1 = Character.isWhitespace(c1);
        boolean b2 = Character.isWhitespace(c2);

        String str1 = "c1 represents Java whitespace character is " + b1;
        String str2 = "c2 represents Java whitespace character is " + b2;

        // print b1, b2 values
        System.out.println(str1);
        System.out.println(str2);
    }
}
Output

:

c1 represents Java whitespace character is true
c2 represents Java whitespace character is false


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4