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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:15:58+00:00 2026-05-29T05:15:58+00:00

I read a file and add it to a list then read the list

  • 0

I read a file and add it to a list then read the list and split the strings and compare it and do somthing with it.
i get this exception:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1

Where should i correct my code?

for (Productname m : listIP) {
        if (m.getIdentifier() == null || m.getProductname() == null) {
                addToNonSimilarList( m.getProductname());
        } else {
            String id = m.getIdentifier().replaceAll("(?<=[A-Za-z])(?=[0-9])|(?<=[0-9])(?=[A-Za-z])", " ").toUpperCase();
            String product = m.getProductname().replaceAll("(?<=[A-Za-z])(?=[0-9])|(?<=[0-9])(?=[A-Za-z])", " ").toUpperCase();
            id = id.replaceAll("\\s+", " ");
            product = product.replaceAll("\\s+", " ");
            if (!id.equalsIgnoreCase(product)) {
                if (id.contains(" X ") && product.contains(" X ")) {
                    String[] ide = id.split(" (?=X\\s*\\d+)");
                    String[] prod = product.split(" (?=X\\s*\\d+)");
                    System.out.println(m.getMnemonic());
                    if (ide.length > 0 && prod.length > 0 && ide[1].trim().equalsIgnoreCase(prod[1].trim())) {
                        String[] i = ide[0].split(" (?=\\d+)");
                        String[] p = prod[0].split(" (?=\\d+)");
                        if (i[0].trim().equalsIgnoreCase(p[0].trim())) {
                            //do nothing
                        } else {
                            addToNonSimilarList( m.getProductname());
                        }
                    } else {
                        addToNonSimilarList( m.getProductname());
                    }
                } else {
                    addToNonSimilarList( m.getProductname());

                }
            }
        }

    }
  • 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-29T05:15:59+00:00Added an answer on May 29, 2026 at 5:15 am

    Well, this condition looks dodgy:

    if (ide.length > 0 && prod.length > 0 
        && ide[1].trim().equalsIgnoreCase(prod[1].trim())) {
    

    You’re testing if there’s at least one element in each, but you’re using the second element in each.

    It’s hard to tell what you’re trying to achieve, but I suspect you either want to change the length conditions or the array indexes. I’d also split this method into shorter ones, and probably create well-named static variables with references to Pattern objects, for clarity…

    EDIT: If you genuinely want to use the second element from each array, I’d suggest:

    if (ide.length > 1 && prod.length > 1 
        && ide[1].trim().equalsIgnoreCase(prod[1].trim())) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read a Resource file in VSTO Shared add-in using the
I read file, but in the end of file i get unknown symbols: int
This is the way I read file: public static string readFile(string path) { StringBuilder
When I using the following code to read file: lines=file(data.txt).read().split(\n) I have the following
I'm having problems reading this one JPEG file using ImageIO.read(File file) - it throws
I tried to read a file in a view like this: def foo(request): f
This program is meant to read in a csv file and create a dictionary
So I have this method that should read a file and detect if the
How do I read an mdb file then pass in the retrieved columns selected
I have a list of options that I read from an xml file. In

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.