URGENT HELP REQUIRED!!! - 'deleting' element from array

Hi

i have written the following method and am wondering if some of the more skilled and knowledgable (more than me i mean) java'ers can check it out and tell me why the value of poss isnt changing as it should:

/* the general idea is that a name of a client is provided to the program,

it should search the arrray, find the client, store their index in poss,

then, starting from poss moving farwards through the array it should

copy the elements back 1 space to write over the 'deleted' client, then to

eliminate the duplicate element on the end transfer it to an array with 1

less space, however, apon debugging i have discovered that poss

doesnt change when the client IS found, i know the client is there as i

entered it myself, can someone tell me why its not finding the client and

storing their index value?*/

publicstaticvoid deleteClient (String name)

{

Client[]c2;

c2 =new Client[c.length-1];

int poss=-1;

for (int i=0;i<noClients;i++)

{

if ((c[i].getName()) == name)

{

poss = i;

}

}

if(poss==-1)

{

System.out.println("Client does not exist");

}

else

{

for (int i=poss;i<noClients;i++)

{

c[i]=c[i+1];

}

}

c2=c;

c=c2;

}

PS; i am not allowed to use Array List for this task unfortunately, so i am stuck with the old stlye Array

Cheers for any help>

[2286 byte] By [Aussie_Nerda] at [2007-11-27 5:39:29]
# 1
Don't mark your post as urgent. We offer our time free of charge and do not take kindly to such requests as "Drop everything and fix my code for me". Also, what makes your problem any more urgent than anyone else seeking help?Use the equals method when comparing objects.
floundera at 2007-7-12 15:14:40 > top of Java-index,Java Essentials,New To Java...
# 2
My Sincerest apologies flounder, i see your point and i take heed, also i figured the .equals method thing out a lil wile ago but my computer's been crashing and hasnt let me come back and say so, so once again my apologies for offending, and thankyou
Aussie_Nerda at 2007-7-12 15:14:40 > top of Java-index,Java Essentials,New To Java...
# 3

For testing String equality use the equals method.

public class ChangingPonies {

public static void main(String[] args) {

String[] names = {

"Jane Seymore", "Cheryl Ball", "Ellen Bicksford", "Anne Farraday"

};

print(names, "Original names array");

String[] afterCheryl = deleteClient(names, names[1]);

print(afterCheryl, "After deleting " + names[1]);

}

private static String[] deleteClient(String[] names, String name) {

String[] temp = new String[names.length-1];

int pos = -1;

for(int i = 0; i < names.length; i++) {

if(names[i].equals(name)) {

System.out.println("Found " + name + " at index " + i);

pos = i;

}

}

if(pos == -1) {

System.out.println("Client not found");

return names;

} else {

for(int i = 0, j = 0; i < names.length; i++) {

if(i == pos)

continue;

temp[j++] = names[i];

}

}

return temp;

}

private static void print(String[] array, String title) {

System.out.print(title + " = [");

for(int j = 0; j < array.length; j++) {

System.out.print(array[j]);

if(j < array.length-1)

System.out.print(", ");

else

System.out.print("]");

}

System.out.println();

}

}

crwooda at 2007-7-12 15:14:40 > top of Java-index,Java Essentials,New To Java...