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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:35:01+00:00 2026-05-27T10:35:01+00:00

This is probably a very simple problem but I’m trying to create an array

  • 0

This is probably a very simple problem but I’m trying to create an array of patterns and there are some issues. What I’ve done is below:

Pattern [] aminos = null;
aminos [0] = Pattern.compile("(gct)|(gcc)|(gca)|(gcg)");
aminos [1] = Pattern.compile("(tgt) | (tgc)");
aminos [2] = Pattern.compile("(gat) | (gac)");

There are no syntax errors or anything before I try to run it, but when I try to run it breaks at the 2nd line saying “Null pointer access: the variable aminos can only be null at this location”. How do I create a Pattern array then? When I neglected to specify null an error appeared asking me to initialise the array, so I’m unsure what to do now.

I guess I could store all the regex patterns in a String Array and then write a small function to form the patterns as needed but it would be more convenient if I could just make a Pattern array.

Thanks for reading guys!

  • 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-27T10:35:02+00:00Added an answer on May 27, 2026 at 10:35 am

    Here’s one simple approach:

    Pattern[] aminos = {
        Pattern.compile("(gct)|(gcc)|(gca)|(gcg)"),
        Pattern.compile("(tgt) | (tgc)"),
        Pattern.compile("(gat) | (gac)")
    };
    

    Alternatively, you could create an array of the right size to start with:

    Pattern[] aminos = new Pattern[3];
    

    That means getting the counting right though – the first version will automatically give you an array of the right size.

    Or use a List<Pattern> instead (the collection classes are generally more pleasant to work with than arrays):

    List<Pattern> aminos = new ArrayList<Pattern>();
    aminos.add(Pattern.compile("(gct)|(gcc)|(gca)|(gcg)"));
    aminos.add(Pattern.compile("(tgt) | (tgc)"));
    aminos.add(Pattern.compile("(gat) | (gac)"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a very simple problem but forgive me as I am new.
This problem is probably very simple to solve but it is not clear to
I'm aware this is probably a very simple problem with a 1-line-of-code answer but
This is probably very simple but it's really confusing me. When I implement the
I know this is probably a very simple question but how would I do
Very simple problem, but can't seem to solve it. I'm probably just not thinking
Really having an issue debugging this...the reason why is probably very simple but I'm
This is probably a very simple and stupid question to ask, but I have
So I've never used XSLT before, so this is probably a very simple problem.
there's probably a very simple solution but I'm at my wit's end here. I

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.