title: Java: How can I check an observable list in Java to make sure it contains at least one value before completing an action?
body: <p>I am fairly new at Java, doing a class project where I need to make a user interface using Java FXML for a company inventory system and then make it workable. I have parts and products that are added, deleted, modified, etc. Each product has a variety of parts and when you modify the product you can add/delete parts. There must be at least one part in the product at all time. </p>
  
  <p>I have a table that represents all of the parts in a particular product, and I need to modify it to where it will not delete a part if it's the only part in the observable list for that product. </p>
  
  <p>Currently I'm using the below to delete the parts which works fine, but obviously does not stop me from fully deleting. I was thinking that using the is.Empty method might help because if it's empty, I can pop up an error saying 'you must have at least one part'. However I'm having trouble implementing that. I was also thinking a while or if/then statement could be useful, because I could just put the segment for deleting inside the while or if/then loop with the condition the observable list isn't empty and the error in the case it is, but I'm not totally sure how I would implement that either and haven't found any resources within my textbooks. I was hoping for a pointer in the right direction, or advice if I'm just completely looking at it the wrong way. </p>
  
  <pre><code>selectedProduct.getAssociatedPart().remove(partsinproduct.getSelectionModel().getSelectedItem());
  </code></pre>