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

  • Home
  • SEARCH
  • 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 7441061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:57:02+00:00 2026-05-29T10:57:02+00:00

I have made an ArrayList in Java and put some integers and some doubles

  • 0

I have made an ArrayList in Java and put some integers and some doubles in it, then I added an array of integers and an array of doubles. Now I have changed a value of one of the doubles that is in the array, and I want to update it. However, I’m having trouble with coming up with the exact syntax for it, since it’s a location within an array within an ArrayList.

To be more specific, I have

ArrayList<Patch> patches; 
patches = new ArrayList<Patch>();  //the ArrayList of patches

int[] VisPatch;  //the array of integers that keeps track of the patchID of the visible patches
double[] formFactor;  //the array of doubles that keeps track of the formFactor for the visible patches

//these are brought in from a file using a scanner
int patchID = fin.nextInt(); //the patch number for each patch in the file
double emissionPower = fin.nextDouble();  //the emission power of the individual patch
double reflectance = fin.nextDouble();  //the reflectance of the individual patch
int numVisPatch = fin.nextInt();  //the number of patches that are 'visible' to this particular patch

//initialize the arrays that hold the visible patch parameters
VisPatch = new int[numVisPatch];
formFactor = new double[numVisPatch];

for(int i=0; i<numVisPatch; i++){
    VisPatch[i] = fin.nextInt(); //brought in from file
    formFactor[i] = fin.nextDouble();
}//end for loop

//create a new patch object from the numbers read in
patches.add(new Patch(emissionPower, reflectance, numVisPatch, VisPatch, formFactor));

//get the first visible patch in the VisPatch array
int adjacentPatchID = patches.get(maxKeyIndex).VisPatch[k]; //maxKeyIndex has been declared, and yes, we're in a for loop that uses k

//do some math on the emissionPower
double increment = 2;
double newEmissionPower = patches.get(adjacentPatchID).emissionPower + increment;

//now update the emission power of the patch
ummm...

I’ve tried

patches.set(adjacentPatchID, newEmissionPower);

and

patches.set(get(adjacentPatchID).emissionPower, newEmissionPower);

and

patches.set(adjacentPatchID.emissionPower, newEmissionPower);

but my IDE (I’m using Eclipse) just put a bunch of red squiggly lines under everything and says I don’t know what I’m talking about (mainly because I don’t).

  • 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-29T10:57:03+00:00Added an answer on May 29, 2026 at 10:57 am

    I’m assuming the thing you want to update is in the Patch class, not in the list of Patches.

    You want to get the patch by ID (assuming your “id” in this case is its position in the list; if not, you might consider using a Map<Integer, Patch> instead) and then mutate it:

    Patch patchToUpdate = patches.get(adjacentPatchId);
    patchToUpdate.emissionPower = newEmissionPower;
    
    //or if it has a proper mutator method:
    patchToUpdate.setEmissionPower(newEmissionPower);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ArrayList in Java, which contains Objects, these Objects are made of
Good evening everyone! I am working on learning some java and I have made
I have a ArrayList made up of different elements imported from a db, made
I have made some code which exports some details of a journal article to
I have made a user control in asp.net c#. Becuase of some data I
In Java, say you have a class that wraps an ArrayList (or any collection)
I have created an arraylist that is made up of custom objects. Basically the
I am using java/blazeds/flex. So basically I have method in java: public ArrayList<Employee> getAllEmployees(){
I have recently started learning Java EE 6 and I could need some help.
I have an ArrayList as an Object(from reflection) and made my own class that

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.