You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
have access to post topics
communicate privately with other members (PM)
not see advertisements between posts
have the possibility to earn one of our surprises if you are an active member
access many other special features that will be introduced later.
I have an array and want to make it generic. Its size is 10 and I want it to either contain int values or string values. Array type depends on the user's selection at runtime.
You can create an object array. If you use the auto boxing feature you can just put any object in the array.
Code:
Object[] data = new Object[2];
data[0] = 10;
data[1] = "hello";
Is this help you?
__________________
Website: To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. - Blog: To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
or u can use the arraylist man..then u can put any type of variable or any type of object into that oone thats useful 2 u i think..
public class Testing
{
public static void main(String args[])
{
Integer i1=new Integer(45);//Integer object
Double d1=new Double(45.567);//double object
String s1=new String("agsd");//string object
Calc c1=new Calc();//object of the class
ArrayList a1= new ArrayList();
a1.add("45");// u can insert direct values also like this
a1.add("a");
a1.add("4de5");
a1.add(45);
a1.add(45.56);
a1.add('a');
a1.add('4');
a1.add("45.79");
a1.add(i1);a1.add(d1);a1.add(s1);
a1.add(c1);