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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:32:45+00:00 2026-05-16T08:32:45+00:00

In my Java application i need to compare two list’s element whether it is

  • 0

In my Java application i need to compare two list’s element whether it is similar or not.

In short suppose i have two list declared like shown below

List<String> a = new ArrayList<String>();
    a.add("one");
    a.add("three");
    a.add("two");
Collections.sort(a);


List<String> a1 = new ArrayList<String>();
    a1.add("ONE");
    a1.add("two");
    a1.add("THREE");
Collections.sort(a);

If i write a condition for equality it fails as some of list’s element is in different case like

if(a.equals(a1)){
    System.out.println("equal");
} else{
    System.out.println("not equal");
}

It will display result “Not equal”

So please tell me how i can make the list element case-insensitive in Java language only.

Thank and regard

  • 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-16T08:32:46+00:00Added an answer on May 16, 2026 at 8:32 am

    Why not using instead a SortedSet with a case insensitive comparator ?
    With the String.CASE_INSENSITIVE_ORDER comparator

    Your code is reduced to

    Set<String> a = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
        a.add("one");
        a.add("three");
        a.add("two");
    
    
    Set<String> a1 = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
        a1.add("ONE");
        a1.add("two");
        a1.add("THREE");
    

    And your equals conditions should work without any issue

    EDIT modified according to comments. Thanks to all of you to correct me.

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

Sidebar

Ask A Question

Stats

  • Questions 541k
  • Answers 541k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need a streaming server: http://en.wikipedia.org/wiki/Comparison_of_streaming_media_systems May 17, 2026 at 2:50 am
  • Editorial Team
    Editorial Team added an answer Wouldn't something like that be working? var test = from… May 17, 2026 at 2:50 am
  • Editorial Team
    Editorial Team added an answer First - do not edit anything in your gem path!… May 17, 2026 at 2:50 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I need to profile a server-client Java application (based on Jersey/REST FYI). I have
I have a Java application with server and Swing client. Now I need to
i'm developing a java application using the jstun library (hxxp://jstun.javawi.de/), and i need to
I am creating a java application and I need to get the user PINs
i need to read an external XML file from my java application in jar
I need something like the C function getservbyname() for a Java application. I've got
I'm going to need to integrate a Java application that I wrote with a
We need an accurate diff utility for Java and Javascript files, written in Java.
I have a Requirement to make an IMAP client as a Web application I
I intend to develop a small (Java) application for managing my finances. I believe

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.