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

  • SEARCH
  • Home
  • 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 6762387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:19:10+00:00 2026-05-26T14:19:10+00:00

I am trying to compare 2 indexes of a string. Basically if the first

  • 0

I am trying to compare 2 indexes of a string. Basically if the first index of a string is not equal to the second index, create new searchIndex() method in void main.

This represents if the user is entering a query in the search engine of 2 words, the results should show the matching text files for the first word and the matching text files for the second word rather than showing the total number of matches and mixing the text files with each other without knowing which word is related to which text file.

If I entered Japan in the textbox

Output:

Searching for 'Japan '
3
Files\whalehunt.txt
Files\japan.txt
Files\innovation.txt

But if I entered 2 words:

Output:

Searching for 'Japan amazon '
5
Files\whalehunt.txt
Files\japan.txt
Files\peru.txt
Files\correspondent.txt
Files\innovation.txt

In case of 2 words, the user is not knowing which word is for which file. It is all mixed up. What I am trying to do is to compare the indexes of the query string to match if the two words are same or not. If not it should add a new searchIndex() method in void main and assign the second word to it.

So rather than this:

public static void main(String[] args) throws Exception {

        createIndex();

        searchIndex("Japan amazon ");

    }

Do this:

 public static void main(String[] args) throws Exception {

            createIndex();

                searchIndex("Japan ");
                searchIndex("amazon");


        }

What I have tried is:

public static void searchIndex(String searchString) throws IOException, ParseException {

        for(int n=0;n<=1000;n++)
        {
            if (searchString.substring(0) != searchString.substring(1))
            {

                void main.searchIndex(searchString.); //**Error**
            }
        }

Any help would be grateful !!

Regards.

  • 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-26T14:19:11+00:00Added an answer on May 26, 2026 at 2:19 pm

    Your serachIndex() method is totally wrong, IMHO. You are comparing indexes 0 and 1 of the string for 1000 times. Why aren’t you using a tokenizer or String.split() to make separate words out of your string? Something like this:

    public static void searchIndex(String searchString) throws IOException, ParseException {
        searchString = searchString.trim();
        if (searchString.length < 1)
            return;
        String[] words = searchString.split(" ");
        if (words.length > 1) {
            for (String word : words)
                searchIndex(word);
        } else {
              // Do normal stuff here
        }
    }
    

    BTW, I assume you are aware of tools like Apache Lucene and algorithms like MapReduce.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to compare two text files and output the first string in
I am trying to compare an index path in my didSelectRowAtIndexPath delegate method with
I am trying to compare a date in SQL and create a new field
I'm trying to compare a string given in an input to a div's content
I am trying to compare a string from getline(file,line) with a std::string s=mmee :
Im trying to compare two different string encoded by sha512. But, result is different.
I'm trying to compare two different object in JSF. A String and an Integer,
I'm trying to compare a character array against a string like so: const char
I am trying to compare std::string s in a locale-dependent manner. For ordinary C-style
I'm basicly trying to compare a token(string) with a hex-datatype! Example: #include<stdio.h> #include<string.h> int

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.