Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Paul Clapham
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Saloon Keepers:
Tim Holloway
Carey Brown
Roland Mueller
Piet Souris
Bartenders:
Forum:
Beginning Java
Need help with Array Code Snippet
Anand Divakaran
Greenhorn
Posts: 11
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi All,
Could somebody explain how new Object[1] and new Object[2] can be used in the below snippet. I understand if new Object(), new Object() was used instead of new Object[1], new Object[2]
public class Practice { public static void main(String args[]) { Object sample [] = {new Object[1], new Object[2]}; } }
Thanks in advance
Anand
Campbell Ritchie
Marshal
Posts: 80871
506
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
An array is in itself an Object.
Object ob = new Object[999]; System.out.printf("ob instanceof Object: %b%n", ob instanceof Object); for (Object obj : (Object[])ob) { System.out.printf("obj instanceof Object: %b%n", obj instanceof Object); /* 999 null references: should print false 999 times */ } ob = new Object[]{"Anand", 123 /* boxed to an Integer */, new Object[3]}; System.out.printf("ob instanceof Object: %b%n", ob instanceof Object); for (Object obj : (Object[])ob) { System.out.printf("obj instanceof Object: %b%n", obj instanceof Object); /* 3 real references: should print true thrice */ }
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Please explain the output
Random access in LinkedList; why not possible
Diff. Between Comparable & Comparator Interface
Abstract class
hashset
More...