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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:36:22+00:00 2026-05-27T03:36:22+00:00

I have two arraylist like this ArrayList<Paragens> paragens = new ArrayList<Paragens>(); ArrayList<Rotas> rotas =

  • 0

I have two arraylist like this

ArrayList<Paragens> paragens = new ArrayList<Paragens>();
ArrayList<Rotas> rotas = new ArrayList<Rotas>();

Paragens is a class and the constructor is

public Paragens(String nomeParagem) {
    this.nomeParagem = nomeParagem;
    this.existeNaRota = new String[]{"","","","","","","","","","","","","",
    "","","","","","","","","","","","","","","","","","","","","","","","",
    "","","","","","","","","","","","","","","","","","","","","","","","",
    "","","","","","","","","","","","","","","","","","","","","","","",""};
    this.id = contadorParagens++;
}

I have another class. The Rotas class.

public Rotas(String nomeRota, Paragens[] nomeParagens) {
    this.nomeRota = nomeRota;
    this.nomeParagens = nomeParagens;
    this.id = contadorRotas++;
}

So there are Paragens (each one with a name[nomeParagem], an id[contadorParagens] and the rotas in wich they exist [existeNaRota].

First, the user inputs Paragens witch are only created with nomeParagem(it’s name) and its id. Since Rotas are added latter, existeNaRota it’s empty.

Each Paragem is then added to paragens arraylist

When user adds an Rotas he inputs Rota name and then the list of Paragens that exist on that Rotas. Rotas are finally added torotas` arraylist.

What I want to do is, when user insert Paragens that exists on one Rotas, existeNaRota is them populated with the Rotas that Paragemexists.

Example.

User inputs some names and then Paragens are created like this:

paragem = new Paragens("London");
paragens.add(paragem);
paragem = new Paragens("Manchester");
paragens.add(paragem);
paragem = new Paragens("Chelsea");
paragens.add(paragem);

Now user will input Rotas like this:

estacoes[0] = "Chelsea";
estacoes[1] = "London";
rota = new Rotas("Route A", estacoes);
rotas.add(rota);

Now, since there is a Rota I want to go back to Paragens and put the name on existeNaRota.

On Paragens I have this set method

public void setExisteNaRota(String existeNaRota, int indice) {
    this.existeNaRota[indice] = existeNaRota;
    indice++;
}

Is it possible to access the paragens arraylist, find the “Chelsea” Paragem and add “Rota A” to the first position of existeNaRota?

  • 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-27T03:36:23+00:00Added an answer on May 27, 2026 at 3:36 am

    First, consider using a List in `Paragens’ instead of an array since you are going to be adding elements to it. This will allow for adding (potentially to the head of the list) without moving elements in the array.

    Second, provide a method in Paragens like addRota(Rota r) that adds the Rota to the List of Rotas in the Paragens.

    class Paragens{
       List<Rota> existEnRota = new ArrayList<Rota>();
    
    
       public void addRota(Rota r){
           existEnRota.add(0, r);
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arraylists, and I would like to have a new arraylist with
I have a problem with comparing two arraylist, my first arraylist looks like this:
I have a array list like this: private ArrayList<Locations> Artist_Result = new ArrayList<Location>(); This
I have read a parent Class called MyClass code like this, public class MyClass
Say I have a generic array like this: ArrayList<Fruit> fruits = new ArrayList<Fruit>(); Then
I have a class like this: @XmlRootElement(name = PricingGroup) public class PricingGroup { ...
So we have a java class with two ArrayLists of generics. It looks like
I have two arrayList ArrayList ar1 = new ArrayList(); ArrayList ar2 = new ArrayList();
I have a class, and list of instances, that looks something like this (field
I have two Java-Classes as follows: public class MyClass { ... } public class

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.