- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create an array of Object in Java
Array of Object class can be created which can accept any type of object. During operation on such array, instanceof operator can be used.
Example
public class Tester { public static void main(String[] args) { Object[] dataArray = new Object[3]; dataArray[0] = new Integer(0); dataArray[1] = new String("1"); dataArray[2] = new Boolean(false); for(Object data: dataArray){ if(data instanceof Integer){ System.out.println(((Integer) data).intValue()); } if(data instanceof String){ System.out.println(data); } if(data instanceof Boolean){ System.out.println(((Boolean) data).booleanValue()); } } } }
Output
0 1 false
- Related Articles
- Create an object array from elements of LinkedList in Java
- How to create an Array in Java?
- How to convert an object array to an integer array in Java?
- How to create an object from class in Java?
- How to create an array of linked lists in java?
- How to create a JSON Array using Object Model in Java?
- How to create an ArrayList from an Array in Java?
- How to convert an object to byte array in java?
- Different ways to create an object in java?
- Create an Integer object in Java
- How to create LabelValue Tuple from an array in Java
- How to create String object in Java?
- How to create date object in Java?
- How to create an Object representation of an Image object using FabricJS?
- How to create an immutable class with mutable object references in Java?

Advertisements