Results 1 to 1 of 1
-
Using reflection to check array type and length
Java Code:import java.lang.reflect.Array; public class ArrayReflection { public static void main(String args[]) { String data[] = new String[3]; data[0] = "Java"; printType(data); } private static void printType(Object object) { Class type = object.getClass(); if (type.isArray()) { Class dataType = type.getComponentType(); System.out.println("Array of: " + dataType); System.out.println(" Length: " + Array.getLength(object)); } } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
Using reflection to create, fill, and display an array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:43 PM -
Need help with creating array of type object
By riz618 in forum New To JavaReplies: 3Last Post: 01-29-2008, 06:14 AM -
How an array can check that profile whether exists or not???
By hien_NU in forum New To JavaReplies: 1Last Post: 01-10-2008, 01:18 AM -
Determining Midi Length
By Usagi in forum New To JavaReplies: 0Last Post: 12-08-2007, 11:45 PM -
Help with method length
By toby in forum New To JavaReplies: 1Last Post: 07-25-2007, 08:29 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks