Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

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.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-21-2007, 11:19 AM
eva eva is offline
Member
 
Join Date: Dec 2007
Posts: 49
eva is on a distinguished road
Generic array
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.

Is this possible?

- PEACE
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-21-2007, 02:19 PM
Senior Member
 
Join Date: Jun 2007
Location: Bali, ID
Posts: 102
wsaryada is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-22-2007, 02:40 PM
khamuruddeen's Avatar
Member
 
Join Date: Dec 2007
Posts: 24
khamuruddeen is on a distinguished road
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);

System.out.println(""+a1);


}
}
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-23-2007, 02:12 AM
eva eva is offline
Member
 
Join Date: Dec 2007
Posts: 49
eva is on a distinguished road
So I can either use ArrayList or use an object array. Thanks for the details.

- PEACE
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A generic framework for a flexible, multi-threaded server Java Tip java.net 0 04-07-2008 10:14 PM
can anyone help... 2d Array Mark1989 New To Java 2 03-12-2008 10:59 PM
Writing generic methods eva New To Java 2 12-31-2007 05:28 AM
Generic Hashtables ShoeNinja New To Java 0 12-05-2007 12:43 AM
Generic Eclipse Modeling System 3.0 RC1 JavaBean Java Announcements 0 10-25-2007 06:25 PM


All times are GMT +3. The time now is 02:39 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org