Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Beginning Java
size of vector
Puneet N Vyas
Ranch Hand
Posts: 61
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Rancher
Posts: 43081
77
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Why should it return 72? You're adding 216 elements to the vector.
Gavin Tranter
Ranch Hand
Posts: 333
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
In total agreement with Ulf, 216 elements should be added.
[ April 08, 2008: Message edited by: Gavin Tranter ]
Christophe Verré
Sheriff
Posts: 14691
16
I like...
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
interface!!!
RLE problem
why hash map contains null
continue blues
hash map error
More...