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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:26:05+00:00 2026-06-13T02:26:05+00:00

I have a small issue when I run into while using arraylists in Java.

  • 0

I have a small issue when I run into while using arraylists in Java. Essentially I am hoping to store an array in an arraylist. I know that arraylists can hold objects, so it should be possible, but I am not sure how.

For the most part my arraylist (which is parsed from a file) is just holding one character as a string, but once in a while it has a series of characters, like this:

    myarray
0    a
1    a
2    d
3    g
4    d
5    f,s,t
6    r

Most of the time the only character I would care about in the string residing at position 5 is the f but occasionally I may need to look at the s or the t as well. My solution to this is to make an array like this:

      subarray
0     f 
1     s
2     t

and store subarray in position 5 instead.

    myarray
0    a
1    a
2    d
3    g
4    d
5    subarray[f,s,t]
6    r

I tried to do this with this code:

 //for the length of the arraylist
 for(int al = 0; al < myarray.size(); al++){
      //check the size of the string
      String value = myarray.get(al);
      int strsz = value.length();
      prse = value.split(dlmcma);
      //if it is bigger than 1 then use a subarray
      if(strsz > 1){
          subarray[0] = prse[0];
          subarray[1] = prse[1];
          subarray[2] = prse[2];
      }
      //set subarray to the location of the string that was too long
      //this is where it all goes horribly wrong
      alt4.set(al, subarray[]);
  }

This isn’t working the way I would like though. It won’t allow me to .set(int, array). It only allows .set(int, string). Does anyone have suggestions?

  • 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-13T02:26:07+00:00Added an answer on June 13, 2026 at 2:26 am

    The easiest approach would be to have an ArrayList of ArrayList.

    ArrayList<ArrayList<String>> alt4 = new ArrayList<ArrayList<String>>();
    

    However, this probably isn’t the best solution. You may want to rethink your data model and look for a better solution.

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

Sidebar

Related Questions

I've run into a small issue here. I have an unsigned char array, and
I have run into a small issue in my program. I have a class
I've run into a small issue for which I have a bit of an
Have run into an issue that i am hoping somebody can help give me
I'm running into a (hopefully) small issue. I have a web app written in
I have seen some SO users run into an issue when trying to use
I have absoulutely no experience with regular expressions, so I've run into a small
I have a small issue I was hoping somebody could help me with. I
I have a small issue with sessions. I have built a small shopping cart-esque
I have a small issue with a method that should save the text contained

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.