Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 716653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:19:25+00:00 2026-05-14T05:19:25+00:00

Related question, about assignment-initialization-declaration. $ javac MatchTest.java MatchTest.java:7: ‘)’ expected for((int i=-1 && String

  • 0

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);
 }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:19:25+00:00Added an answer on May 14, 2026 at 5:19 am

    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 for bound in a local variable:

    String s = "Hello";
    for (int i = 0, L = s.length(); i < L; i++) {
        System.out.println(s.charAt(i));
    } // prints "H", "e", "l", "l", "o"
    

    This is a common idiom for mapping a 1D-2D array:

    int[] arr1d = new int[9];
    int[][] arr2d = {
        { 1, 2, 3 },
        { 4, 5, 6 },
        { 7, 8, 9 },
    };
    for (int r = 0, i = 0; r < 3; r++) {
        for (int c = 0; c < 3; c++) {
            arr1d[i++] = arr2d[r][c];
        }
    }
    System.out.println(Arrays.toString(arr1d));
    // prints "[1, 2, 3, 4, 5, 6, 7, 8, 9]"
    

    This idiom of two iterators coming in from both ends is also common:

    boolean isPalindrome(String s) {
        for (int i = 0, j = s.length() - 1; i < j; i++, j--) {
            if (s.charAt(i) != s.charAt(j)) {
                return false;
            }
        }
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This maybe a related question: Java assignment issues - Is this atomic? I have
My question is about restoring complex activity related data when coming back to the
This question is directly related to this SO question I posed about 15 minutes
This is related to this question I asked earlier about syntax highlighting user-defined blocks
Somewhat related to this question , but in the absence of any answer about
I was posting some comments in a related question about MVC caching and some
(this is related to another question about implementation on iPhone) I have a large
I have a question about best practices related to de-normalization or table hierarchy relationships.
I can't find a related question to give me an idea about how to
There's a related question What is the preferred Java XML binding framework? In the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.