Ask Experts Questions for FREE Help !
Ask
    maduro's Avatar
    maduro Posts: 1, Reputation: 1
    New Member
     
    #1

    Nov 9, 2013, 08:08 PM
    How to delete an object from an array (from index , int count)
    Public void deleteObjects(int index, int count) {
    if (index < currentObjectt){
    for(int I = count; I < myObjects.length - 1; I++){
    myObjects[i] = myObjects[i + 1];
    }
    currentObject = myObjects.length - (count * index);
    }
    }

    how come that I am not using (int index) at all?
    9hththt2's Avatar
    9hththt2 Posts: 59, Reputation: 1
    Junior Member
     
    #2

    Nov 10, 2013, 10:10 AM
    What do you intend to do, exactly?
    You can set that array position to NULL; is that what you want?

    myObjects[idx] = null;
    9hththt2's Avatar
    9hththt2 Posts: 59, Reputation: 1
    Junior Member
     
    #3

    Nov 10, 2013, 11:13 AM
    Please let me help you.

    Considering the name of your method, "deleteObjects", I think what you are trying to do is delete "N objects" from an array, starting at a given index. Is that right?

    I don't understand what is your "currentObject" variable for, though.

    If what you are trying to do is this (what I understood), then you should consider looking at it this way:

    First you need to check if the " index " parameter is valid for that array "myObjects".
    If the "index" is out of your array's bounds (if it's less than 0, or higher than the length of your array), then you should RETURN from the method.
    You should also check if "index+count-1" (which would be the last index that you want to "remove" from the array) is in the array's bounds. If not, you can Return from the function too.

    You can't remove elements from an array, because arrays have a static dimension. You can only set the positions to NULL, like this:
    myArray[i]=null;
    But you can "redefine" your old array, by creating a new array, with the correct new dimension, and copying the elements that are important, from the old(original) array, ignoring the ones you wish to "remove". This way, you get a new array without the elements that you wished to remove. Then you just have to do something like:
    originalArray = newArray;

    Please check this.
    [Java] deleteObjects-Remove "count" integers from array, from index - Pastebin.com

    I pasted it here for you; it's a solution to this problem that I just made, and hope it helps.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

A change in the gravitation force acting on an object will affect the object's [ 1 Answers ]

A.mass B.coefficient of static friction C.weight D.inertia

I received a final judgment by defaul on count 1 on a 2 count lawsuit [ 0 Answers ]

1st count has been set by default On the second count my attorney told me that we have a trail date on Friday (nov 4th which I understood it was in front of a jury) somehow today he tells me we do not have the right to a jury trial What is the reason for this?

The object doesn't contain the Automation object '|.' [ 1 Answers ]

Hello, And thank you for taking this question. I currently support a small Access system and ran into the error mentioned in the title. I believe that the issue is system-specific because I ran the system from my desktop and printed fine. The issue centers around the cmdPrint command function. ...


View more questions Search