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 07-31-2008, 07:14 AM
Member
 
Join Date: Jul 2008
Posts: 24
bri1547 is on a distinguished road
Help with Arrays
I am working on a program where I need to put objects into an array through a four-argument constructor. I want to use a multi-dimensional array to store the data. The problem I am having is that everything I have read about arrays uses the same variable type for he entire array. I need to store 2 string variables, an int variable, and a double variable. How can I accomplish this?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-31-2008, 07:42 AM
Member
 
Join Date: Jul 2008
Posts: 19
thusa is on a distinguished road
You can only define an array of one specific type no matter whether it's a multi-dimension or not.

Like; Object[][] myAr = new Object[5][];

In your situation, there are two options for you.
1. Write a bean with all those four fields and use that as the type of your array.
2. Define the array as Object type (show above), and store the values as you wish. But I do not recommend this since it would have type issues later.

So best would be to write a small bean class with those for fields.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-31-2008, 04:37 PM
Member
 
Join Date: Jul 2008
Posts: 24
bri1547 is on a distinguished road
Number one, I have no idea what a "small bean class" is! And number two, i have already partially developed the program and all I can do now is create an array to hold the information. This small bean thing sounds really interesting, though. I sure would like to know what it is all about.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-31-2008, 05:10 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Remove the word bean.
Create a small class that holds all the different data types. Then you can make objects with the class that will hold your data and that you can put into an array of that type (type== your class)
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-01-2008, 07:12 AM
Member
 
Join Date: Jul 2008
Posts: 19
thusa is on a distinguished road
Exactly as Norm said, it will be a class with four variables to hold the values that you are planning to store in your multidimensional array.

Eg:

Code:
public class ArrayData{ private int index; private int count; private String name; private String group; //methods to get and set those values public void setIndex(int i) { this.index = i; } public int getIndex() { return this.i; } //add get and set methods for other three fields as well }
Even though you have already done parts of the program, this will not raise issues, since you just have to create a new instance of ArrayData class and set those values there; then set this object into your array.

Now your array need not to be multidimensional.

Hope this will help you.
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
arrays hasysf New To Java 12 07-28-2008 04:38 AM
need help with arrays Jman New To Java 17 07-21-2008 04:34 AM
Arrays bunbun New To Java 1 04-09-2008 04:24 AM
new to arrays jimJohnson New To Java 1 04-08-2008 04:45 PM
2D-Arrays kbyrne New To Java 1 02-08-2008 12:08 AM


All times are GMT +3. The time now is 01:26 AM.


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