Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2005

Tip: Looking for answers? Try searching our database.

Can I borrow your eyes for debuging  (Vector inside Vector)?

Thread view: 
RC - 27 Sep 2005 14:56 GMT
private Vector<Vector<String>> vector;
....

vector = new Vector<Vector<String>>();
int index = 0;
while (index < 5) {
  vector.elementAt(index).addElement(new Vector<String>());
   index++;
}

This is the compiled error, please tell me what's wrong.

addElement(java.lang.String) in java.util.Vector<java.lang.String>
cannot be applied to (java.util.Vector<java.lang.String>)
            vector.elementAt(ct).addElement(new Vector<String>());

Thank Q very much for your eyes in advance!
Ingo R. Homann - 27 Sep 2005 15:12 GMT
Hi,

> private Vector<Vector<String>> vector;
> ....
[quoted text clipped - 13 lines]
>
> Thank Q very much for your eyes in advance!

Well, "vector.elementAt(index)" returns a "Vector<String>", on this you
cann call "addElement()", but this will of course require a String to be
added.

Ciao,
Ingo

PS: Additionaly, use ArrayList, which is not synchronized, instead of
Vector.
Roedy Green - 27 Sep 2005 20:05 GMT
>int index = 0;
>while (index < 5) {
>   vector.elementAt(index).addElement(new Vector<String>());
>    index++;
>}
This is beside your problem, but how does your loop ever terminate?
Normally you use a FOR loop for that sort of thing.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Jeffrey Schwab - 28 Sep 2005 03:11 GMT
>>int index = 0;
>>while (index < 5) {
[quoted text clipped - 4 lines]
> This is beside your problem, but how does your loop ever terminate?
> Normally you use a FOR loop for that sort of thing.

The loop terminates when index is no longer strictly less than five.
Since index is initialized to zero, then incremented once per loop
iteration, the loop will end after five iterations.

I almost never use for-loops.  I get the idea of groupin' the loopin',
but I don't like the idea of having multiple statements on a single
line.  Separating the statements onto separate lines is ugly, too:

for (initialize();
    test();
    increment()) {
    // ...
}
Roedy Green - 28 Sep 2005 03:24 GMT
>I almost never use for-loops.

That is naughty. It is code obfuscation technique.
See http://mindprod.com/jgloss/unmain.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Jeff Schwab - 28 Sep 2005 03:38 GMT
>>I almost never use for-loops.
>
> That is naughty. It is code obfuscation technique.
> See http://mindprod.com/jgloss/unmain.html

You think while loops are obscure?  Wow.
Roedy Green - 28 Sep 2005 03:54 GMT
>You think while loops are obscure?  Wow.

Yes, when used for counted loops. They are normally used for loops
that do not stop on a count. There is a standard idiom for doing
something N times with an index running 0..n-1 and it is not an while
loop.  Doing that sort of stunt is inconsiderate of those who have to
read or maintain your code.

Unlike English, in code, you want to be trite.

There was a similar weird loop posted today.

for ( int n=0, n<5001; n++ )

n is traditionally the count. i the index.  Violating that convention
trips someone up reading the code.

I guess this bugs me more than it does others because of my Fortran
and Forth background where the convention is  rigidly followed.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Jeff Schwab - 28 Sep 2005 04:15 GMT
>>You think while loops are obscure?  Wow.
>
[quoted text clipped - 4 lines]
> loop.  Doing that sort of stunt is inconsiderate of those who have to
> read or maintain your code.

A while loop isn't a "stunt," it's a code construct.  Stunts typically
involve hoops of fire, or professional drivers on closed courses. :)

Anyway, I get that you like to use for-loops to count.  Good for you.  I
don't.  By expressing an opinion, I did not mean to criticize yours.
Move on.

> Unlike English, in code, you want to be trite.

"Trite?"  ITYM "terse."  And by "you want to be," ITYM "I want you to be."

> There was a similar weird loop posted today.
>
> for ( int n=0, n<5001; n++ )
>
> n is traditionally the count. i the index.  Violating that convention
> trips someone up reading the code.

I do typically follow that convention, but not always.  It doesn't get
my goat, but I understand your point of view.

> I guess this bugs me more than it does others because of my Fortran
> and Forth background where the convention is  rigidly followed.

I didn't realize the Forth community had quite agreed on the syntax of
the language, much less established rigid code conventions.  My
impression was that many Forth programmers began each program by
implementing a compiler.  Not to put down the language or community at
all; Forth is something I really would like to learn if I ever find the
time.
Roedy Green - 28 Sep 2005 06:50 GMT
>> Unlike English, in code, you want to be trite.
>
>"Trite?"  ITYM "terse."  And by "you want to be," ITYM "I want you to be."

What I mean is you must write code in a stereotypical way. You want to
"blend" . You write code the way everyone else does. Coding is not
novel-writing. People don't want to linger over your code and enjoy
the nuance. They want to be able to rapidly eyeball it and grasp the
meaning quickly.

If you avoid the common idioms you slow people down.  

Most coding is not a solitary activity.  You have to get along with
fellow team members which means everyone coding in a similar style.
Wherever you work the standards imposed will be slightly different.
The exact rules are much less important than the fact everyone agrees
to follow them.  Ditto code indentation and spacing.

Further, even if you code alone, still likely others will eventually
see your code.  You should not get into idiosyncratic habits.

All you do is make it harder for others to understand your code.

It is not a matter of your way vs my way. It is a matter of following
conventions vs you playing artiste.

I know being conventional feels sinful, especially to the young,  but
there are times when it is appropriate.  Think of it as form of
consideration for others rather than a damper on your creativity.  If
you want to be creative, express it elsewhere than making pointless
variations on common idioms.

I am not going to leave this alone.  I have been coding myself 42
years. I have made those exact same mistakes and had people trip over
my fancy-pants code. I know how being coerced rankles, but writing in
a standard way really does matter.

Look at Sun's code. You will not see any of their programmers avoiding
common idioms.  That is part of what design patterns is all about,
making code more boring.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Jeff Schwab - 28 Sep 2005 17:06 GMT
>>>Unlike English, in code, you want to be trite.
>>
[quoted text clipped - 5 lines]
> the nuance. They want to be able to rapidly eyeball it and grasp the
> meaning quickly.

Where do you get off telling me what I want?

> If you avoid the common idioms you slow people down.  

I prefer "while" to "for."  By using a for-loop aren't you avoiding the
simpler and even more canonical while-loop?

> Most coding is not a solitary activity.  You have to get along with
> fellow team members which means everyone coding in a similar style.
> Wherever you work the standards imposed will be slightly different.
> The exact rules are much less important than the fact everyone agrees
> to follow them.  Ditto code indentation and spacing.

Thanks for the lecture.

> Further, even if you code alone, still likely others will eventually
> see your code.  You should not get into idiosyncratic habits.

Like using while-loops?

> All you do is make it harder for others to understand your code.
>
> It is not a matter of your way vs my way. It is a matter of following
> conventions vs you playing artiste.

"Playing artiste?"  You think I'm dancing around the computer with a
beret tilted jauntily on my head, and a rose clenched between my teeth?

> I know being conventional feels sinful, especially to the young,  but

I would love to know how old you imagine I am. :)

> there are times when it is appropriate.  Think of it as form of
> consideration for others rather than a damper on your creativity.  If
> you want to be creative, express it elsewhere than making pointless
> variations on common idioms.

As much as I would like to take credit for bing creative, I did not
invent the while-loop.

> I am not going to leave this alone.  I have been coding myself 42
> years. I have made those exact same mistakes and had people trip over
> my fancy-pants code. I know how being coerced rankles, but writing in
> a standard way really does matter.

I have yet to see a standard that required me to use a particular kind
of loop, though I certainly *have* seen standards that avoided do-while
loops and other language features perceived as being unnecessary or
redundant.

> Look at Sun's code. You will not see any of their programmers avoiding
> common idioms.

You would have if you had looked during the four years I worked there.

> That is part of what design patterns is all about,
> making code more boring.

Design Patterns are a fascinating field of study, but they're really not
related to what we're discussing.  We're talking about a built-in
feature of many popular programming languages.  Aren't we?
Roedy Green - 28 Sep 2005 23:15 GMT
>> I know being conventional feels sinful, especially to the young,  but
>
>I would love to know how old you imagine I am. :)
maybe 17.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Jeff Schwab - 28 Sep 2005 23:17 GMT
>>>I know being conventional feels sinful, especially to the young,  but
>>
>>I would love to know how old you imagine I am. :)
>
>  maybe 17.

Are you serious, or are you being deliberately insulting?
Roedy Green - 29 Sep 2005 02:27 GMT
>Are you serious, or are you being deliberately insulting?
What is insulting about being 17?  I would give my eye teeth to be 17
again.  Mathematicians do their best work in their teens and early
twenties.

You have such a strong distaste for convention I figured it could be
general teen rebellion or inexperience with the consequences. That is
roughly how I felt at 17.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Jeff Schwab - 29 Sep 2005 02:43 GMT
>>Are you serious, or are you being deliberately insulting?
>
[quoted text clipped - 5 lines]
> general teen rebellion or inexperience with the consequences. That is
> roughly how I felt at 17.

I don't have any distaste for convention.  I just find multiple
statements on a single line of code distasteful, even in a for loop.
Don't read anything into it.

If people were not dissatisfied with the existing state of the art,
there would be no progress.  Wild whippersnappers, flouting convention
by restricting their code to their preferred subset of language features
, may be preferable to gurus exploiting features even they don't really
understand.

I may not have as much industry experience as yourself; forty-two years,
did you say?  Far fewer for me, but the same number of digits, and I
know what a Hollerith card is.  And I, for one, would not want to be 17
again: no college degree, no salary, and no wife.
Monique Y. Mudama - 29 Sep 2005 16:19 GMT
["Followup-To:" header set to comp.lang.java.help.] On 2005-09-29,
Roedy Green penned:

>>Are you serious, or are you being deliberately insulting?
> What is insulting about being 17?  I would give my eye teeth to be
[quoted text clipped - 4 lines]
> general teen rebellion or inexperience with the consequences. That
> is roughly how I felt at 17.

I read it more as "No one can tell me what to do!  I've been there and
done that and gotten the teeshirt!" -- definitely a mentality I
associate with older people, and more specifically my dad =P

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Jeffrey Schwab - 28 Sep 2005 03:39 GMT
Jeff Schwab wrote:

> Roedy Green wrote:
>
[quoted text clipped - 7 lines]
>
> You think while loops are obscure?  Wow.

Whoops, you didn't say obscure, you said "obfuscated."  Still: Wow.  
Anyway, I reserve the right to avoid constructs I find messy, including
most for loops.
Roedy Green - 28 Sep 2005 04:14 GMT
>Anyway, I reserve the right to avoid constructs I find messy, including
>most for loops.

You have that right in your own code that you don't broadcast.  But
you most certainly don't have that right if you ever work on a team.
You will get fired quickly if you persist after a warning.

If you post such code I also have the right to throw tomatoes at it
attempting to dissuade others from following your example.

Have a look at point 34 in http://mindprod.com/unmainobfuscation.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Jeff Schwab - 28 Sep 2005 04:18 GMT
>>Anyway, I reserve the right to avoid constructs I find messy, including
>>most for loops.
>
> You have that right in your own code that you don't broadcast.  But
> you most certainly don't have that right if you ever work on a team.
> You will get fired quickly if you persist after a warning.

Really?  Maybe you should call my boss, and make sure he realizes he
should have fired me years ago.  Tell my teammates to get outraged, too.

> If you post such code I also have the right to throw tomatoes at it
> attempting to dissuade others from following your example.
>
> Have a look at point 34 in http://mindprod.com/unmainobfuscation.html

No thanks.  I've already wasted enough time following your "mindprod"
links.  Not that they're all bad, but using them to answer usenet posts
all the time is annoying, like someone who insists on posting in HTML.
E11 - 28 Sep 2005 06:03 GMT
I agree with Jeff on his last point. While i think its good site, it
does *seem* a tad like you are using every opportunity to direct
traffic there, and it can be annoying for people like me with a slow
connection.

Anyhow, regarding the use of a while-loop where a for-loop would do, i
do not see a problem with the while-loop UNLESS the body of the
while-loop is long and the variable increment statement can't be easily
seen.

while (index < 5) {
 vector.elementAt(index).addElement(new Vector<String>());
 index++;
}

This seems fine to me. (The use of the while-loop that is.) The
"index++" seems obvious enough, and it is quite easy to see that the
loop is not endless and will terminate after 5 iterations.
Roedy Green - 28 Sep 2005 07:11 GMT
>I agree with Jeff on his last point. While i think its good site, it
>does *seem* a tad like you are using every opportunity to direct
>traffic there, and it can be annoying for people like me with a slow
>connection.

That is illogical.  It takes about the same bandwidth to get material
from my site as from a newsgroup. My way cuts down your total
bandwidth since you don't have to look at what is not a pressing
concern to you.  You can just mentally file it away for future
reference or ignore it.

I try to give a short answer and a link. If the question comes up
frequently I dispense with the short answer and just give the link.

The advantages of the links are:

1. I can properly format my answers.

2. I can use tables, colour, bold , fonts etc to enhance my answer.

3. I have previously answered this question and done a more thorough
job of answering it on the website than I could come up with off the
top of my head.  

4. You might get the hint that most questions are already answered
there if you just looked up the right keyword.

5. I can go on at great length on my website answering the question
without wasting bandwidth of people who are not interested in that
level of detail.

6. The website is not a commercial website in the ordinary sense.. All
it does it pay the ISP bill. It does not even cover my Internet
access.  It exists as a favour to people like you, whether they see it
that way or not.  People ask a question. I point them to the answer. I
am not extracting any money out of them when they visit the website.
Even if you download my utilities, all come with source.  Paying for
the few that are shareware is purely optional.

7. The website is full of hyperlinks to hyperlinks to help you find
related information, including the relevant Sun docs.

8.  I have already answered many of the questions.  I have been doing
this since the days of Java 1.0. Why should I have to compose a novel
response to the same old questions?

9. My glossary entries have been previously viewed by many people and
are more likely been through the mill and corrected and augmented and
completed than something I type off the top of my head.

Perhaps what is bugging you is that you are having to cut and paste
the link to a browser to view it and it takes a long time for the page
to come up.  You resent that waste of your time.  Fair enough. You can
download a copy of the website and keep it up to date using the
Replicator. Then you have instant access. No charge.  See
http://mindprod.com/webstarts/replicator.html

Also you might look into a different newsreader that just lets you
click a link to view it. see
http://mindprod.com/jgloss/newsreader.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Monique Y. Mudama - 28 Sep 2005 15:31 GMT
["Followup-To:" header set to comp.lang.java.help.] On 2005-09-28,
Roedy Green penned:

>>I agree with Jeff on his last point. While i think its good site, it
>>does *seem* a tad like you are using every opportunity to direct
[quoted text clipped - 6 lines]
> pressing concern to you.  You can just mentally file it away for
> future reference or ignore it.

I assumed he meant the number of link-only posts, not the length of
the posts.  If he has his client set to only d/l a message when he
views it, then it may seem annoying to go to that trouble just to see
a link you've already seen many times before.

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Roedy Green - 28 Sep 2005 23:25 GMT
>I assumed he meant the number of link-only posts, not the length of
>the posts.  If he has his client set to only d/l a message when he
>views it, then it may seem annoying to go to that trouble just to see
>a link you've already seen many times before.

In that case his complaint would equally apply also to answers he has
heard many times before. His real beef is with people who keep asking
commonly asked questions without using a suitable title line.

If you use Agent, you get to see ahead of time how many lines are in a
post.  You can avoid long ones or one-liners if you want that way.

I suspect the real beef is  my volume or perhaps my sexual preference
which often gets people in a knot even when the subject has nothing to
do with sex.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Jeff Schwab - 28 Sep 2005 23:32 GMT
>>I assumed he meant the number of link-only posts, not the length of
>>the posts.  If he has his client set to only d/l a message when he
[quoted text clipped - 11 lines]
> which often gets people in a knot even when the subject has nothing to
> do with sex.

I have no idea what your sexual preference is, and frankly, I'd like to
keep it that way.
Monique Y. Mudama - 29 Sep 2005 00:11 GMT
> I suspect the real beef is  my volume or perhaps my sexual
> preference which often gets people in a knot even when the subject
> has nothing to do with sex.

I haven't seen anything posted on this newsgroup, nor anything in any
of the links you've posted, having anything to do with your or anyone
else's sexual preference, so I'm going to go out on a limb here and
say that most of us hadn't even given it a thought until you mentioned
it just now.

Prejudice is a reality, but I don't think it's a factor in this case,
unless you've disclosed some sort of personal information elsewhere
and think this guy saw it.

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Roedy Green - 29 Sep 2005 05:23 GMT
>Prejudice is a reality, but I don't think it's a factor in this case,
>unless you've disclosed some sort of personal information elsewhere
>and think this guy saw it.

I get it more in the political newsgroups where people use only ad
hominem arguments.  They must spend days souring for tidbits to use
and twist.

I don't know why they bother. Most of them just make stuff up out of
thin air anyway.

I remember once working on a banking project where the boss was doing
something incredibly stupid (hard coding banking logic in spaghetti in
hundreds of separate places so it was impossible to maintain when the
logic changed) . The more I argued, the more firmly he dug in his
heels.  I finally decided the if the project failed it would not be
the end of the universe.  I did not have the power to override my
boss.

Then as the crunch was coming I noticed boss had secretly capitulated
and was working nights to do as I had asked.  I was unwittingly
blocking him from doing the right thing because I did not give him a
way out that would let him save face.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 28 Sep 2005 07:14 GMT
>Anyhow, regarding the use of a while-loop where a for-loop would do, i
>do not see a problem with the while-loop UNLESS the body of the
>while-loop is long and the variable increment statement can't be easily
>seen.

Eventually you will come around, but apparently that day is a few
years off.  Non-standard code bites the author too eventually.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Jean-Baptiste Nizet - 28 Sep 2005 08:46 GMT
I agree with Roedy here. Besides being not "standard", it also puts the
index variable in the outer scope, instead of tying it inside the loop
scope. This is bad practice.

JB.
Roedy Green - 28 Sep 2005 10:07 GMT
>I agree with Roedy here. Besides being not "standard", it also puts the
>index variable in the outer scope, instead of tying it inside the loop
>scope. This is bad practice.

You can't use the while count idiom twice in a row since you can't
redeclare the index variable in the same scope.

There is also the general rule that it is best to narrow the scope of
a variable to the absolute minimum.  Making it overly broad just
creates opportunities for unintended interactions, or other uses being
overlooked in maintenance.  And for those not afraid of Knuth, it
suppresses various optimisations, such as putting an indexing value
purely in a register.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Stefan Schulz - 28 Sep 2005 21:16 GMT
> You can't use the while count idiom twice in a row since you can't
> redeclare the index variable in the same scope.

You should not do that anyway, since an inner loop iterating with the same
variable will invariable cause confusion to the reader.

> There is also the general rule that it is best to narrow the scope of
> a variable to the absolute minimum.  Making it overly broad just
> creates opportunities for unintended interactions, or other uses being
> overlooked in maintenance.  And for those not afraid of Knuth, it
> suppresses various optimisations, such as putting an indexing value
> purely in a register.

Any compiler worth its salt will recognize the life of the variable ends
with the block, and starts with its initialization. Instruction reordering
previous to register allocation will likely produce the exact same code,
(which the register allocator then maps to registers as it sees fit in its
infinite wisdom ;) )

Signature

You can't run away forever,
But there's nothing wrong with getting a good head start.
          --- Jim Steinman, "Rock and Roll Dreams Come Through"
         

Roedy Green - 28 Sep 2005 23:52 GMT
>Any compiler worth its salt will recognize the life of the variable ends
>with the block, and starts with its initialization. Instruction reordering
>previous to register allocation will likely produce the exact same code,
>(which the register allocator then maps to registers as it sees fit in its
>infinite wisdom ;) )

Early my career I worked on number crunching programs for the local
electric utility that took many hours to compete. The game was looking
for yet another way to speed them up.  I would look at the assembler
generated by IBM's Fortran H  and PL/1 compilers to see what sort of
optimisations they would make.  So often they would miss "obvious"
ones.  Then you have to imagine being the compiler without the extra
knowledge you have about what pathological things could happen, and
allow yourself to get paranoid. Then you discover the most innocent
little things could inhibit an optimisation.

Java is nicely designed from an optimising compiler's point of view,
but still I think that general observation would still apply.  If you
can keep code simple and non-intertwined, the optimising compiler will
be able to do more with it.

But even more important, keeping variables as local as possible is a
great boon to the maintenance programmer. It allows him to IGNORE
hunks of code.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 28 Sep 2005 07:38 GMT
>> You have that right in your own code that you don't broadcast.  But
>> you most certainly don't have that right if you ever work on a team.
>> You will get fired quickly if you persist after a warning.
>
>Really?  Maybe you should call my boss, and make sure he realizes he
>should have fired me years ago.  Tell my teammates to get outraged, too.

I have found there are basically three kinds of places to work.

1. loosey goosey places where the boss does not care about code
quality at all, just deadlines and lines of code produced.  You end up
fighting with him over wanting to do things properly.

2. places run by genius tyrants.  They want to control your every
move. You fight with him over leaving you alone in things that are
none of his business, e.g. which IDE you use or your keyboard layout.

3. bureaucracies. See Dilbert.

Though (2) are frustrating at the time, you do learn a lot being
forced to do things new ways, and of course you can feel proud of the
product.

One genius type I worked for had the rule "blend".  He said "I don't
want to be able to tell who wrote a given piece of code just by
looking at the code itself".  He had many rules to ensure that was so.
He and I disagreed on the amount of commentary necessary but the nice
thing about the code was everything was beautifully consistent across
all manner of apps.  He could put an team member to work on any app
and they were very quickly at home.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 28 Sep 2005 07:58 GMT
>No thanks.  I've already wasted enough time following your "mindprod"
>links.  Not that they're all bad, but using them to answer usenet posts
>all the time is annoying, like someone who insists on posting in HTML.

By that you could mean:

1. you wasted your time because you followed the link with a question
in mind and the material at the link did not answer your question.  If
you mean that, please email me with the question an entry did not
answer and I will do something about it. I do this many times a day
for other people.

2. you wasted time because of the time it takes to put the link in
your browser and download the entry.  I suggested in another response
you try the local Replicator mirror for faster response. see
http://mindprod.com/jgloss/replicator.html

Links are terse.  HTML is unreadable bulk for most newsreaders. I
don't see why you consider them analogous other than you don't like
them both.

Are you seriously suggesting I should post the CONTENTS of every
glossary entry every time I now post a link?    Surely the screams
would be ten times louder. You don't post something that has been
posted before. That is spam.

What I am doing is a slightly more polite version of "reading the
f.cking faq".  I provide a link to the page they need to read. I used
to just give the keyword until people complained.

It is just my links that bug you, or links in general?

Perhaps it bugs you that I have an canned answer to so many questions
on tap. I have been doing this for ten years now.  It just adds up.
Except for questions about specific third party packages there is not
that much new in Java itself each day.

I am here primarily to help fledgling programmers in the third world.
They often cannot afford text books. They have to make do with my
glossary entries and the online docs they point to.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 29 Sep 2005 00:00 GMT
>No thanks.  I've already wasted enough time following your "mindprod"
>links.  Not that they're all bad, but using them to answer usenet posts
>all the time is annoying, like someone who insists on posting in HTML.

If you like, we could mutually filter each other. Then you will never
see any of my link answers, and I will never see any of your eccentric
Java code.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Jeff Schwab - 29 Sep 2005 03:17 GMT
>>No thanks.  I've already wasted enough time following your "mindprod"
>>links.  Not that they're all bad, but using them to answer usenet posts
[quoted text clipped - 3 lines]
> see any of my link answers, and I will never see any of your eccentric
> Java code.

I thought about it, but you post on a lot of threads, and seem to help
people frequently.  I think if I plonked you, I would be missing a
significant part of the dialogue here.  If you're really irked by
"eccentric" posts that don't include for-loops, you're probably better
off ignoring me entirely. :)  Here's one for the road:

import java.io.PrintWriter;

public class For {
        public static void main(String[] args) {
                PrintWriter out = new PrintWriter(System.out);

                for(;;) {
                        out.println("Goodbye, cruel world!");
                }
        }
}
Todd de Gruyl - 28 Sep 2005 06:24 GMT
>>Anyway, I reserve the right to avoid constructs I find messy, including
>>most for loops.
>
> You have that right in your own code that you don't broadcast.  But
> you most certainly don't have that right if you ever work on a team.
> You will get fired quickly if you persist after a warning.

I have to agree with Roedy here.

> Have a look at point 34 in http://mindprod.com/unmainobfuscation.html

This link doesn't work (404).  ITYM
http://mindprod.com/jgloss/unmainobfuscation.html

--
Todd de Gruyl
Roedy Green - 28 Sep 2005 07:18 GMT
>http://mindprod.com/jgloss/unmainobfuscation.html

I keep doing that .  I am trying to get it the habit of testing every
link before I hit Send.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 27 Sep 2005 20:17 GMT
>vector = new Vector<Vector<String>>();
>int index = 0;
>while (index < 5) {
>   vector.elementAt(index).addElement(new Vector<String>());
>    index++;
>}

Nesting discombobulates the human mind.

Just what are you trying to add an element to?

1. an inner vector to the outer vector?

2. a string to an inner vector at a particular slot?

Which do you want?  The following  does compile.

import java.util.Vector;
public class NestedVectors

  {

  private static Vector<Vector<String>> vector;

  /**
   * test harness
   *
   * @param args not used
   */
  public static void main ( String[] args )
     {
     vector = new Vector<Vector<String>>(5);
     for ( int i=0; i<5; i++ )
        {
        // add inner Vector to outer Vector
        vector.add( new Vector<String>() );
        // add String to inner vector
        vector.elementAt(i).addElement( "bananas" );
        }
     }
  }

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

RC - 27 Sep 2005 20:42 GMT
> Just what are you trying to add an element to?

Try to make a table(or net), one row of Vectors(or ArrayLists),
each column also add Vectors<String>(or ArrayLists<String>).

> 1. an inner vector to the outer vector?
>
> 2. a string to an inner vector at a particular slot?
>
> Which do you want?  

I think both.
RC - 28 Sep 2005 12:24 GMT
Thank Q to Roedy's hint below.
I compiled my program without errors, now.
You can rest your eyes for now untill next
time I need to borrow again.

> The following  does compile.
>
[quoted text clipped - 22 lines]
>       }
>    }
John C. Bollinger - 28 Sep 2005 03:11 GMT
> private Vector<Vector<String>> vector;
> ....
[quoted text clipped - 11 lines]
> cannot be applied to (java.util.Vector<java.lang.String>)
>             vector.elementAt(ct).addElement(new Vector<String>());

As Roedy was hinting, you are confused about what {type of) element
you're adding to which Vector.  Here is an equivalent piece of (still
buggy) code:

private Vector<Vector<String>> vector;

// ...

vector = new Vector<Vector<String>>();

for (int index = 0; index < 5; index++) {
    Vector<String> element = vector.elementAt(index);

    element.addElement(new Vector<String>());
}

If you don't recognize the error in that then see what the compiler has
to say about it (much the same as before, actually, but note which line
is flagged).

Signature

John Bollinger
jobollin@indiana.edu



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.