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 09-06-2008, 08:55 AM
Member
 
Join Date: Jul 2008
Posts: 26
aneesahamedaa is on a distinguished road
Adding elements to an Object Array
Hi all,
I have created an object array
Code:
Object elements[][] = { {"first.doc","first.doc"}, {"second.pdf","second.pdf"}, {"third.txt","third.txt"} };
Now, how will I create an array as shown above when the names("first.doc","second.pdf","third.txt") come inside a vector?

The vector will be as given
Vector v = new Vector();
v.add("first.doc");
v.add("second.txt");
v.add("third.pdf");
How will I create the array(by iterating through the vector with for loop)?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-06-2008, 12:10 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,545
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
What you asking is not clear here. Do you want to add elements to a vector and iterate through that?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

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 09-06-2008, 12:43 PM
Member
 
Join Date: Jul 2008
Posts: 26
aneesahamedaa is on a distinguished road
Quote:
Originally Posted by Eranga View Post
What you asking is not clear here. Do you want to add elements to a vector and iterate through that?
Please see how I created the array first
Code:
Object elements[][] = { {"first.doc","first.doc"}, {"second.pdf","second.pdf"}, {"third.txt","third.txt"} };
It was coded manually. Now that I have the data to create an array similar to the one above inside a vector.
ie; v.elementAt(0) will be "first.doc" v.elementAt(1) will be "second.pdf" and so on.
My question is, how to create the object array with the elements from this vector(using a for loop to add elements to the array from vector)

Kindly say if my point is not clear.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-06-2008, 01:29 PM
Member
 
Join Date: Jul 2008
Posts: 26
aneesahamedaa is on a distinguished road
Ok,
I got it solved myself
Object elements[][] = new Object[v.size()][2];
for(int i =0; i<v.size(); i++)
{
elements[i][0] = v.elementAt(i).toString();
elements[i][1] = mc.getIcone(mc.getExtension(v.elementAt(i).toStrin g().toUpperCase()));
}

Thanks for the help.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 09-07-2008, 05:55 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,545
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
I don't know exactly what you are going to do. But seems to me you are trying to keep a record pair each time.

Anyway, on the for loop you can still use the array length property.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

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
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
How to check whether two elements are available in an array? venkatteshb New To Java 8 08-28-2008 12:45 AM
reference to elements in array Igor New To Java 1 12-14-2007 01:56 PM
problems with asigning elements of an array to a constructor rednessc New To Java 1 12-14-2007 09:25 AM
Adding listener to non-Java object? cruxblack Advanced Java 5 07-30-2007 04:19 AM
Help with array of elements zoe New To Java 1 07-24-2007 07:33 PM


All times are GMT +3. The time now is 12:37 AM.


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