reset password
Author Message
JCA08
Posts: 12
Posted 20:40 Sep 03, 2017 |

I am having trouble understanding the following:

  • The SimpleSet class shall have a private data field which is an array of 10 elements to store each element of the Set.  HINT: Take a look at the source code for ArrayList and see how they create the internal array for ArrayList.  This array will be fixed at 10 and WILL NOT resize itself.  We are creating a very simple set to hold only 10 items.

I took a look at the ArrayList source code and I think it's a 1D array of Objects. Is this the way we should implement it in our SimpleSet? 

HuyNguyen
Posts: 4
Posted 20:48 Sep 03, 2017 |

yeah!

kknaur
Posts: 540
Posted 08:40 Sep 04, 2017 |
JCA08 wrote:

I am having trouble understanding the following:

  • The SimpleSet class shall have a private data field which is an array of 10 elements to store each element of the Set.  HINT: Take a look at the source code for ArrayList and see how they create the internal array for ArrayList.  This array will be fixed at 10 and WILL NOT resize itself.  We are creating a very simple set to hold only 10 items.

I took a look at the ArrayList source code and I think it's a 1D array of Objects. Is this the way we should implement it in our SimpleSet? 

Yes this is correct.  Keep in mind that even though the array stores Objects, you still want to use the generic type where applicable.  You may need to also do some casting within your SimpleSet class, but you shouldn't need to do any casting outside of the class.