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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:09:52+00:00 2026-06-17T12:09:52+00:00

I essentially need to know if I can change 1 arrayList into another arrayList

  • 0

I essentially need to know if I can change 1 arrayList into another arrayList and then make an association as to which item in arrayList 1, an item from arrayList 2 came from, without using a pattern finder. It is difficult to explain, so let illustrate it with a simple example:

Given file input:

Feline:
Cat Lion
Cheetah

Canine:
Dog
Wolves Fox

I split the file into each paragraph using:

String strLine;
String [] paragraph = strLine.split("");

From here I add each item to an arrayList by using an add method inside an advanced for loop.

This should leave us with the first arrayList:

[Feline: Cat Lion Cheetah, Canine: Dog Wolves Fox]

From there in need to split each item into separate words, using the regex \\s+. This should be easy with another advanced for loop.

This should leave us with the second arrayList:

[Feline:, Cat, Lion, Cheetah, Canine:, Dog, Wolves, Fox]

What I need to know is if there anyway for me to get the program to realise that the word Cheetah in the second arrayList originated from the first item in the first arrayList, without having to search the first arraylist for items in the second arrayList. The point has to be that the the one item in the one arrayList originates from the other arrayList.

I essentially need to do this because I have methods that depending what the the first word of each paragraph is, different things are done to each paragraph.

Let me know if my explanation is confusing and sorry about bad terminology, I’m having trouble explaining my problem.

If this is possible please let me know how I might go about solving my problem.

Regards

  • 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-17T12:09:54+00:00Added an answer on June 17, 2026 at 12:09 pm

    I would propose to keep the initial array list position when you do the split based on the space character. Say for example you define an object as follows;

    public class MyWord
    {
    private int pos;
    
    private String word;
    public MyWord(int pos,String word)
    {
     this.pos = pos;
    
     this.word = word;
    }
    //getters and setters
    } 
    

    Then when you split, you can do something like this;

    List<MyWord>secondList = new ArrayList<MyWord>();
    for(int i=0;i<firstList.size();i++)
    {
     String[]words = firstList.get(i).split("\\s");
     for(String wordToAdd : words)
     {
      MyWord w = new MyWord(i,wordToAdd);
      secondList.add(w);
     }
    }
    

    So now your second list will have an object containing the word as well as the original index it contained in the first list.

    Hops this helps.

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

Sidebar

Related Questions

Essentially I want a border-less, black window which I can set the location and
I'm trying to change a listbox in my main form from another file (nodes.cs)
Simple one I think but essentially I need to know what the syntax is
So I essentially need to do this: String text = line1\n; text += line2\n;
I need to parse a simple statement (essentially a chain of function calls on
Essentially, I need to parse the response string of the CHAT CREATE command with
I've got a bit of a problem. Essentially, I need to store a large
Essentially, I'm looking for a 1D bar-code scanner that I can program, either through
Essentially, is there any way to make this code legal? main = print .
Essentially I'd like to know just how compatible are the iPhone and the iPod

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.