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 8841715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:47:22+00:00 2026-06-14T10:47:22+00:00

Hello fellow programmers, I would like to ask for some help with regards to

  • 0

Hello fellow programmers,

I would like to ask for some help with regards to near matches of strings.

Currently, I have a program that stores strings of description, users can search for description by typing it completely or partially.

I would like to implement a near match search. For example the actual description is “hello world” but user erroneously enter a search “hello eorld”. The programs should be able to return “hello world” to user.

I’ve tried looking at pattern and matches to implement it, but it requires a regex to match strings, whereby my description does not have a regular pattern. I’ve also tried string.contains, but it doesn’t seems to work either. Below is part of the code i tried to implement.

    ArrayList <String> list = new ArrayList<String>();
    list.add("hello world");
    list.add("go jogging at london");
    list.add("go fly kite");
    Scanner scan = new Scanner(System.in);

    for(int i = 0; i < list.size(); i++){
      if(list.get(i).contains(scan.next())) {
         System.out.println(list.get(i));
      }
    }

Could fellow programmers help me with this??

  • 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-06-14T10:47:23+00:00Added an answer on June 14, 2026 at 10:47 am

    You can use LCS(Longest Common Subsequence) see these:
    http://en.wikipedia.org/wiki/Longest_common_subsequence_problem

    public class LCS {
    
        public static void main(String[] args) {
            String x = StdIn.readString();
            String y = StdIn.readString();
            int M = x.length();
            int N = y.length();
    
            // opt[i][j] = length of LCS of x[i..M] and y[j..N]
            int[][] opt = new int[M+1][N+1];
    
            // compute length of LCS and all subproblems via dynamic programming
            for (int i = M-1; i >= 0; i--) {
                for (int j = N-1; j >= 0; j--) {
                    if (x.charAt(i) == y.charAt(j))
                        opt[i][j] = opt[i+1][j+1] + 1;
                    else 
                        opt[i][j] = Math.max(opt[i+1][j], opt[i][j+1]);
                }
            }
    
            // recover LCS itself and print it to standard output
            int i = 0, j = 0;
            while(i < M && j < N) {
                if (x.charAt(i) == y.charAt(j)) {
                    System.out.print(x.charAt(i));
                    i++;
                    j++;
                }
                else if (opt[i+1][j] >= opt[i][j+1]) i++;
                else                                 j++;
            }
            System.out.println();
    
        }
    
    }
    

    Other solution is Aho–Corasick string matching algorithm see this :
    Fast algorithm for searching for substrings in a string

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

Sidebar

Related Questions

Hello fellow programmers. I have a SQL Server 2005 query that is taking a
Hello fellow programmers, I have made a function that looks up the database if
Hello fellow programmers I have been searching the internet for a few days now
Hello fellow programmers. I have a question about static and the dot operator using
Hello fellow C++ programmers. I have, what I hope to be, a quick question
Hello fellow StackOverflowers! I have some information in a database that I need pulled
Hello my fellow programmers, I have a problem (other than not knowing enough) I
Hello Fellow Computer People! Anyone willing to help will have my gratitude ;) Just
hello fellow java developers. I'm having a bit of an issue here. I have
Hello fellow software developers. I want to distribute a C program which is scriptable

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.