method call problems

I have two classes

class one contains
-Array with content
-Method to print the array

class two contains
-methods to manipulate the array in class 1
-calls the one.print

The problem is:
To print the manipulated array made by the methods in class 2, by calling the print method in class one.
I just get the default content when doing that.
m-jansenAsked:
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.

aozarovCommented:
Are you sure you are manipulating directly the array that class one holds?
0
m-jansenAuthor Commented:
The array updated with the new content.
0
m-jansenAuthor Commented:
I think the problem is that I make a new instance when calling the print method
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

aozarovCommented:
If you create a new array then make sure you are assiging the new array to class one array variable.
I hope the following is clear to you that it is a mistake and will not change the class one array:

in class two:
method XXX
{
array x = class one.array;
x = new array;
}
0
mightyoneCommented:

Your code should look somehow like this....

class A{
public String [] str = new String {"empty","full","full"};

public print(int i){
if (i > str.length){i = 0;}
System.out.println(i+"  :  "+str[i]);
}
}

class B{

private A classA = new A();
public B(){}
set(String s, int idx){
A[idx] = s;
}

public static void main(String args[]){
B classB = new B();
b.set("full",0);
b.print(0);
}}


}



if not change your array to static and it will work, but then you really have to make sure ONLY one Thrrad is manipulating your array.....
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
aozarovCommented:
I guess mightyone ment to write:

classA.str[iidx] = s;

instead of
>> A[idx] = s;


0
mightyoneCommented:
of course sorry for that ;-)
0
mightyoneCommented:
and change
set(String s, int idx){
A[idx] = s;
}
to

public void set(String s, int idx){
A[idx] = s;
}
0
m-jansenAuthor Commented:
Thanx
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.