The 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 AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor
