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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:13:56+00:00 2026-05-31T18:13:56+00:00

I’ve been racking my brain for the past hour wondering how to do this.

  • 0

I’ve been racking my brain for the past hour wondering how to do this. It’s more of a logic question than a technical question I think.

I have two strings and wish to count how many characters they have in common. I.e Emily + Andy = 1.

I thought I could maybe convert the strings to char arrays and use two For statements within each other to go through each possibility, but I’m not 100% on how I’d do that. I’ve scoured Google for an answer but I’m not getting anywhere.

I apologize for not providing any code, I don’t currently have any. I’m fairly new to Java and I’m not sure how to go about this.

Anyone have a solution?

  • 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-31T18:13:57+00:00Added an answer on May 31, 2026 at 6:13 pm

    First you have to remove duplicate letters in both strings, and then you have to compare. The below code is working fine.

    public class CountDuplicates {
    
        /**
         * Author Krishnan
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            String str1 = "palani";
            String str2 = "krishnan";
            String str11 = "";
            String str12 = "";
            char[] ch1 = str1.toCharArray();
            char[] ch2 = str2.toCharArray();
            int count = 0;
            for(int i=0; i<ch1.length; i++)
            {
                if(!str11.contains(ch1[i]+""))
                {
                    str11 += ch1[i];
                }
            }
            for(int i=0; i<ch2.length; i++)
            {
                if(!str12.contains(ch2[i]+""))
                {
                    str12 += ch2[i];
                }
            }   
            char[] ch11 = str11.toCharArray();
            char[] ch12 = str12.toCharArray();
            for(int i=0; i<ch11.length; i++)
            {
                for(int j=0; j<ch12.length; j++)
                {
                    if(ch11[i] == ch12[j])
                    {
                        count++;
                    }
                }
            }
            System.out.println("Duplicate Letters: " + count);
        }
    
    }
    

    Output:

    Duplicate Letters: 3

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.