A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
size of vector
Puneet N Vyas
Ranch Hand
Joined: Sep 20, 2007
Posts: 61
posted
Apr 08, 2008 01:55:00
0
what defines the size of the vector,i get two conflicting o/p by the following code,can any one tell me.
thanks for support
String items[] = {"a","b","c","d","e","f"}; Vector Candidate3=new Vector(); for(int ii=0,kk=0; ii<6; ii++) { for(int jj=0;jj<6;jj++,kk++) { for(int ll=0;ll<6;kk++,ll++) { Candidate3.add(items[ii]+" "+items[jj]+items[ll]); } } } //displaying vector contents for (int i = 0; i < len1; ++i) { String s1=(String)Candidate3.get(i); System.out.println(s1); int ij= Candidate3.indexOf(s1); System.out.println(ij); } //this gives size of vector as 216,where as it should give 72 as there are //72 index in the vector System.out.println("length of vector Candidate 3 is"+Candidate3.size()); Vector v11=new Vector(); v11.add("pfg"); v11.add("dfg"); //this gives size of vector as 2 System.out.println("length of vector v11:"+v11.size());
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35224
7
posted
Apr 08, 2008 02:00:00
0
Why should it return 72? You're adding 216 elements to the vector.
Android apps
–
ImageJ plugins
–
Java web charts
Gavin Tranter
Ranch Hand
Joined: Jan 01, 2007
Posts: 333
posted
Apr 08, 2008 02:03:00
0
In total agreement with Ulf, 216 elements should be added.
[ April 08, 2008: Message edited by: Gavin Tranter ]
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14670
11
I like...
posted
Apr 08, 2008 02:28:00
0
You could try to count the number of times you loop :
int total = 0; for(int ii=0,kk=0; ii<6; ii++) { for(int jj=0;jj<6;jj++,kk++) { for(int ll=0;ll<6;kk++,ll++,total++) { Candidate3.add(items[ii]+" "+items[jj]+items[ll]); } } } System.out.println("Looped " + total + " times");
[My Blog]
All roads lead to JavaRanch
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: size of vector
Similar Threads
continue blues
RLE problem
why hash map contains null
hash map error
interface!!!
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter