1
I was wondering if I could get some kind of control variable, from a for
"advanced".
For example:
In a be normal, I do it this way:
for (int i = 0; i < algumaCoisa.size() ou length; i++){
//código..
}
this variable i
I can use to go through the components, example:
((JComponent) componentes.get(i)).requestFocus();
in a be advanced I would do:
for(MeuComp comp: componentes){
//código..
}
How would I get the position that the for
is and traverse all components?
Obs: MeuComp
is an interface that contains methods, which are implemented by components such as JTexefield
, JComboBox
and etc. componentes
is a List
of these components, but I believe that was not so important, the example may be on top of anything.
Thank you all !
– JavaTech
How do you know
componentes
has aindexOf()
? Even if you do, you know the cost of it?– Maniero
I don’t know, since the example is simple, I just gave him a tip in case he needs it. In this case the cost does not matter, because the knowledge that it is possible is worth more.
– Marcus Hert da Coregio
@bigown by what I understood of the question(and by what I already answered of this OP),
componentes
is aList
.– user28595
@Articuno It may be, but it does not have in the question, but seeing what cost (exponential, by the way) does not matter gave that dry swallowed.
– Maniero
@bigown I don’t know why all the fuss, this question is more like some academic activity or something. If it was for any activity that performance really mattered, he wouldn’t be asking that.
– Marcus Hert da Coregio
@Marcusdacorréggio is that in my conception the right is always the right and always desirable, teach the right to those who are starting is the best to do. I think it’s a shame that you think teaching anyway is ideal.
– Maniero
@bigown at no time did I say that was ideal. I just showed him that there is possibility. I agree with you, we should always teach the right thing. But to recognize right, we also need to be aware of wrong, even if not so wrong...
– Marcus Hert da Coregio
Nesse caso o custo não interessa, pois o conhecimento de que é possível **vale mais**
Andessa pergunta tá mais pra alguma atividade acadêmica
this leaves implicit that for being academic can do anyway, when it should be the opposite, since it is a time to learn the right.– Maniero
@bigown you who interpreted something implicit, I had no intention. The academic environment must learn right and wrong. Each with his own opinion, the important thing is that he had his answer. Hug.
– Marcus Hert da Coregio