Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
determining an object class is an array, list etc
Inggo Riviera
Greenhorn
Posts: 6
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
How do I easily determine an object is an array of objects, list of objects or a class of the collection classes? Could you please show me a sample code.
Thanks,
Inggo
gaurav abbi
Ranch Hand
Posts: 108
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
try using reflections for this, just a simple call will do
there's method in object class which will help you..
thanks,<br />gaurav abbi
Jesper de Jong
Java Cowboy
Posts: 16084
88
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You can use the instanceof operator:
Object obj = ...; if (obj instanceof Object[]) { System.out.println("It is an array of objects!"); } else if (obj instanceof List) { System.out.println("It is a List!"); } else if (obj instanceof Collection) { System.out.println("It is a collection!"); } else { System.out.println("It is something else!"); }
Jesper's Blog
-
Pluralsight Author Page
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Reflection problem...new one
Copy existing Array into new ArrayList
convert array to Arraylist
emptying an array
Doubt in Arrays.asList()
More...