how can i remove an array from an array?

I don't understand how to locate and remove an object from an array of integers?

  • Please help! This question uses the programing language of JAVA. If you can explain it to me and give me good websites as resources, that would be much appreciated! Thanks!

  • Answer:

    It sounds like you need to review the basics of the language. In Java, integers (small i) are "primitives", and are not objects. So, you would never be able to remove an object from an array of integers, because it could never hold them. On the other hand, an Integer (capital I) IS an object. Further, an array (little a) is not an object but an ArrayList is, meaning they would have different ways to find and remove elements. I would suggest the first link for tutorials from Sun, and the second link to find references to the version of Java you are using. Try reviewing the materials about arrays, then post what you think the first step toward the answer is.

Kitty at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

I have no f'n clue.

Chris

Example array of integers: Integer[] a = { new Integer(32), new Integer(21) } To access the elements: a[0] a[1] You cannot remove them directly. If you do not want to shrink the array size, just make it zero, such as, a[1] = new Integer(0); If you want to shrink the array size and remove a[1] from the array for example, there's no direct way. You need to write a method to do it.

an

Jeez, it's not like she asked us to do her homework, like most everyone else. Anyway, to take out an element from an array, you have to copy the next element into the element you want to get rid of, then copy the next element into the space of the element you just moved, and so on. Arrays can't be resized, so this doesn't change the amount of memory used. Check out the collections interfaces for more functional ways of storing data. And yes, you should probably be picky about what you call an object, because it does make a difference in Java. int []intArray = {1,2,3,4,5,6}; int indexToRemove = 3; // or whatever for (int i = indexToRemove;i < intArray.length-1;i++) { intArray[i] = intArray [i+1]; } intArray[intArray.length-1] = 0;

Whatever

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.