Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
String Contain Substring or not in Java

Actually i am facing a problem in comparing string in java. The problem is that i have Arraylist type list which contain some employee designation but designation may be developer or Junior developer or may be Sinior developer type designation my problem that consider all developer designation as a only developer so i use this code for this.

ArrayList<String> al_designation = ret.getDesignationListFromRegistration();
int ii = 0;
for (String designation : al_designation) {
    ii++;
    for (int j = ii; j < al_designation.size(); j++) {
        if (designation.toLowerCase().contains(al_designation.get(j).toLowerCase())) {
            al_designation.remove(j);
        }
    }
}

enter image description here

enter image description here

What i want all HELPER type designation consider only HELPER, Same for STITCHER all type STITCHER.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Add required items from your ArrayList to a HashMap as follows:

    ArrayList<String> al_designation = new ArrayList<>(Arrays.asList("Developer", "Junior Developer",
            "Senior Developer", "Senior Architect", "Junior Manager", "Senior Manager", "Assistant Manager", //
            "CEO", "Tech Lead", "Dev Lead"));
    System.out.println(al_designation);// Before it contains all
                                        // designations.

    Map<String, String> map = new LinkedHashMap<>();
    for (String designation : al_designation) {
        designation = designation.toLowerCase();
        String[] words = designation.split(" ");
        String lastWord = words[words.length - 1];
        String value = map.get(lastWord);
        if (value == null)
            map.put(lastWord, designation);
        else
            map.put(lastWord, lastWord);
    }
    al_designation.clear();
    al_designation.addAll(map.values());
    System.out.println(al_designation);// Now it contains only required designations. 
                                        //This is your answer.
over 4 years ago · Santiago Trujillo Report

0

I don't know what are you trying to accomplish however you can check if your string e.g. "Junior developer" contains substring "developer" like this:

if (str1.toLowerCase().contains(str2.toLowerCase())){
    // do whatever you need to do
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!