java - How to remove object from array -


Please understand it; Because it can be difficult to understand

I have a Jabatone 50 size big, for this example Ill use is 7 jbutton object within 7 I 1 2 3 4 6 7, but not 5. They are printed on the screen. I want to remove these jbuttons, but all 5 buttons are removed, while the last two are not. For <

  (int i = 1; i <51; i ++) {if (seat.buttonArray [i] == faucet) {remove (seat.buttonArray [i] ); Seat.buttonArray [i] = null;}}    

Remove element to array , suppose that the subsequent indexes have been changed after the removal. For this purpose, you should use the list :

  Iterator Butitator = seat.buttonList.iterator (); While (ButtonErterator hasNext ()) {Object Button = Buttitter.Next (); // or more specific type, if your list is generated (button == blank) {// or some other criteria, it is written as an example example Iterator.remove (); }}   

If it is mandatory to use array , you have two options:

  • set seat .buttonArray [i] to the null value, it has been pointed out that it has been removed;
  • See Javadok for details, although I do not recommend this approach due to performance approaches.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -