Results 1 to 5 of 5
- 09-06-2008, 07:55 AM #1
Member
- Join Date
- Jul 2008
- Posts
- 26
- Rep Power
- 0
Adding elements to an Object Array
Hi all,
I have created an object array
Java Code:Object elements[][] = { {"first.doc","first.doc"}, {"second.pdf","second.pdf"}, {"third.txt","third.txt"} };
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)?
- 09-06-2008, 11:10 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
What you asking is not clear here. Do you want to add elements to a vector and iterate through that?
- 09-06-2008, 11:43 AM #3
Member
- Join Date
- Jul 2008
- Posts
- 26
- Rep Power
- 0
Please see how I created the array first
Java Code:Object elements[][] = { {"first.doc","first.doc"}, {"second.pdf","second.pdf"}, {"third.txt","third.txt"} };
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.
- 09-06-2008, 12:29 PM #4
Member
- Join Date
- Jul 2008
- Posts
- 26
- Rep Power
- 0
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.
- 09-07-2008, 04:55 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
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.
Similar Threads
-
How to check whether two elements are available in an array?
By venkatteshb in forum New To JavaReplies: 8Last Post: 08-27-2008, 11:45 PM -
reference to elements in array
By Igor in forum New To JavaReplies: 1Last Post: 12-14-2007, 12:56 PM -
problems with asigning elements of an array to a constructor
By rednessc in forum New To JavaReplies: 1Last Post: 12-14-2007, 08:25 AM -
Adding listener to non-Java object?
By cruxblack in forum Advanced JavaReplies: 5Last Post: 07-30-2007, 03:19 AM -
Help with array of elements
By zoe in forum New To JavaReplies: 1Last Post: 07-24-2007, 06:33 PM
Bookmarks