Add to string array

I know the size of my array but how do I know where to put it in?

Let say I got

House[] house    //size 4

now I want to do this

public void addHouse(House myhouse){
  How do I know where to put it in. I dont wanna write over someting
that already exists.
      
}
MickeysAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cmalakarCommented:
You need to maintain a instance variable which keeps track of how many objects have added.
and use that to update the array.

Ex..

Class X{
int nextArrayPosition = 0;
House[] house = new House[10];

public void addHouse(House myhouse){
house[nextArrayPosition] = myhouse;
//Now increment the nextArrayPostion
nextArrayPosition = nextArrayPosition + 1;
}
}
0
MickeysAuthor Commented:
so there is no other way? I dont know how have written this exercises. They dont seem to know java though.
0
cmalakarCommented:
>> so there is no other way?

Are you asking that.. you still dont know the size of the array ?
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

MickeysAuthor Commented:
well what i have done is brought the size into the constructor now and done this

public class HouseLIst{

      private House[] houses;
      static int nextArrayPosition = 0;
      
      public HouseList(int size){
            houses= new House[size];
      }
      
but I get this:
org.eclipse.debug.core.DebugException: com.sun.jdi.ClassNotLoadedException: Type has not been loaded occurred while retrieving component type of array.
0
cmalakarCommented:
the above is perfect.. problem somewhere .

Complete program may help us.
0
MickeysAuthor Commented:
Mail? I can send it in a zip.
0
cmalakarCommented:
can't attach here ?
0
MickeysAuthor Commented:
No it always complains about format and stuff. So fastest way mail. Would be kind if that worked for you
0
cmalakarCommented:
I am not very sure.. if sending to mails.. violates the ee rules.
0
MickeysAuthor Commented:
it doesnt. Anyway...check your gmal. :-)
0
cmalakarCommented:
First obversation.. found this.

SIZE variable is never assigned with a value.  And you array size is 0, that might be the problem.

>> ResultList resultList= new ResultList(SIZE);

should be

 ResultList resultList= new ResultList(rawResults.length);   // right ?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MickeysAuthor Commented:
You are so right. Been sitting here since the morning so you get blind. So now I onyl got the sort. I have tried diffrent things but ending up with deleting the code. Do you got any suggestions?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.