i need only an example for deleting with shift in an array because i can't get it
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
i need only an example for deleting with shift in an array because i can't get it
Java lover
Please see the link in my signature entitled 'Getting Help'...you need to provide a lot more information if you wish to receive replies that aren't simply guesses.
i think (she?) means having a regular array, and wanting to use it as a list. so if she wants something in the middle deleted, she wants help moving the rest of the array over.
If this isnt specifically being asked for by the teacher, use ArrayList, it does all that for you.
otherwise say you want to delete the 4th index of an array named myArray
posDeleted = 3
for(int i=posDeleted; i< // the arrays length;i++)
{
myArray[i] = myArray[i+1];
}
something like that, but I have not used arrays for this job in a while so i forget the way to find out its length.
also, i should never reach the last index of the array, it should only reach the second last(because it grabs from one index higher)
also, you may want to make a new array that is smaller by 1 and be sticking everything in the new array to prevent lots of invalid data at the end not getting over ridden, or you can just write code to handle the last spot of the array and set it to a flag such as -1 or null
keep smiling (February 26th, 2012)
If someone wants their question to be answered concisely, then they should not assume we are mind readers and should provide all the information necessary. Feel free to guess, but given the information provided that is all it is at the moment - could be right, and could be wrong as shift could mean a great many things - moving array elements, deleting from an array using the shift key, and that doesn't even address what it means to delete (shorten an array, nullify elements, etc...). I say this because this poster has provided limited information in the past, and should learn that getting answers is intimately tied to how the question is asked.
keep smiling (February 26th, 2012)
ok i got the information i need
and i won't make my question too general again to find the wanted answer
Java lover