This week's book giveaway is in the Kotlin forum.We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# array subtraction

TIM SAN
Greenhorn
Posts: 2
Hello I'm trying to make a number list in which users picks a number from a list of 9 then the number is removed from the list how would i go about doing this?

pete stein
Bartender
Posts: 1561
have a look at ArrayList. This will probably have all you need.

Ranch Hand
Posts: 1585
Hi,

As a matter of fact, this can be done in various ways, one of these ways is to use the ArrayList class.

Take a look at the Collections Framework.

Good luck ...

TIM SAN
Greenhorn
Posts: 2
would this work

marc weber
Sheriff
Posts: 11343
Originally posted by TIM SAN:
would this work

How could you write code to test this?

Srikanth Ramu
Ranch Hand
Posts: 76
You can either construct a new int[] by adding all the elements except 8th element or as mentioned above you need to createan ArrayList by adding all the elements of "number" and then use "remove" method.

fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
I don't think the original problem is well defined. if this were my original array:

{1,2,3,4,5,6,7,8,9}

and the user enters a '3', what EXACTLY should the array look like? Are you removing the third element? are you removing the element with the index of 3? or are you removing elements that contain the value of '3' - and if so, do you do the first, the last, or all of them?

if you do want to remove the element, should you then collapse the remaining values? in other words should you have this:

{1,2,0,4,5,6,7,8,9}

or this:

{1,2,4,5,6,7,8,9}

 It is sorta covered in the JavaRanch Style Guide.