Java determines whether an object is a string
Nov 23, 2019 am 09:35 AMThe instanceof operator in java is used to indicate at runtime whether an object is an instance of a specific class. instanceof returns a Boolean value indicating whether the object is an instance of this specific class or a subclass of it.
Usage:
result = object instanceof class
Parameters:
Result: Boolean type.
Object: required. Any object expression.
Class: required. Any defined object class.
Description:
If object is an instance of class, the instanceof operator returns true. Returns false if object is not an instance of the specified class, or if object is null.
Example:
class Main { public static void main (String[] args) { String name = "Programiz"; Integer age = 22; System.out.println("Is name an instance of String: "+ (name instanceof String)); System.out.println("Is age an instance of Integer: "+ (age instanceof Integer)); } }
When we run the program, the output will be:
是name的String的实例:true age是Integer的实例:true
In the above example, we have created an object in the name String type and an Integer type of the age of another object. We then use the instanceof operator to check if the name is of type String and the age is of type Integer.
For more java knowledge, please pay attention to java basic tutorial.
The above is the detailed content of Java determines whether an object is a string. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Break or return from Java 8 stream forEach?
