In Perl you can write something like
while(!eof){
doSomething(x,y);
print $_;
}
and the second statement prints out the iteration the loop is up to using $_
, the name of the invisible variable Perl uses to iterate through the loop. What is the name of that variable in Java?
I realise that you can accomplish the same thing by declaring a variable outside the loop and incrementing it, but this way is definitely more elegant if anyone knows how to do it.
There's no implicit variable in Java as in Perl. You just have to be more explicit in Java...
There is no such concept in Java.
In Groovy, at least you get an it
variable set on the functional methods.
myList = [1,2,3];
myList.each {
println it
}
or to read a file, like in your example...
new File('test.txt').eachLine {
println it
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With