Related question, about assignment-initialization-declaration.
$ javac MatchTest.java
MatchTest.java:7: ')' expected
for((int i=-1 && String match="hello"); (i=text.indexOf(match)+1);)
^
MatchTest.java:7: ';' expected
for((int i=-1 && String match="hello"); (i=text.indexOf(match)+1);)
^
MatchTest.java:7: ';' expected
for((int i=-1 && String match="hello"); (i=text.indexOf(match)+1);)
^
MatchTest.java:7: not a statement
for((int i=-1 && String match="hello"); (i=text.indexOf(match)+1);)
^
MatchTest.java:7: illegal start of expression
for((int i=-1 && String match="hello"); (i=text.indexOf(match)+1);)
^
5 errors
$ cat MatchTest.java
import java.util.*;
import java.io.*;
public class MatchTest {
public static void main(String[] args){
String text = "hello0123456789hello0123456789hello1234567890hello3423243423232";
for((int i=-1 && String match="hello"); (i=text.indexOf(match)+1);)
System.out.println(i);
}
}
You can’t declare and initialize a variable of a second type, but you can have multiple variables (possibly with initialization) of the same type.
This is a common idiom of caching a
forbound in a local variable:This is a common idiom for mapping a 1D-2D array:
This idiom of two iterators coming in from both ends is also common: