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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:29:00+00:00 2026-06-12T16:29:00+00:00

I have an array of Strings called letters . When I try to execute

  • 0

I have an array of Strings called letters. When I try to execute the following line of code, I get a NullPointerException.

if(letters[j].equals(tmpst))

Where j is an arbitrary index less than the length of letters

tmpst is a string that is defined as such:

char myChar = theWord.charAt(i);
String tmpst = String.valueOf(myChar);

where theWord is an arbitrary string with length greater than 4.

The full code is:

for (int i = 0; i < theWord.length(); i++) { 
        for (int j = 0; j < letters.length; j++) { 

            char myChar = theWord.charAt(i);
            String tmpst = String.valueOf(myChar);

            if(letters[j].equals(tmpst)) { 
                System.out.println("YOU DIDIT!!! :D");
                newWord = newWord + theWord.charAt(i);
            }

        }

Can someone see what I’m doing wrong?

Thanks.

  • 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-12T16:29:01+00:00Added an answer on June 12, 2026 at 4:29 pm

    It seems that your array contains some null references. You can use Arrays.toString(letters) to see if it is true.

    If you want that your comparisson still works even if your array contains null values, you should change your code to be like this:

    if(tmpst.equals(letters[j]))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Specifically, I have an array of strings called val, and want to replace all
I have an array of strings of random letters, and I need to know
I have an array of strings and an IQueryable (called MyTypeQbl). I want to
I have a model that has an array of Strings called tags, public class
I have an object called SampleObject that holds an array of strings called StringArray.
I have an array of strings, called @theModels, in a routine implemented as part
Say I have an array of strings in a php array called $foo with
I have an array called as myArr . It contains strings and integers, e.g.
I have array of strings, String[] data and it's 10 elements has value P
I have an array of strings var controlsToGet = new[] {lblHome,lblContact}; I have List<LanguageControl>

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.