Why this code is giving NZEC error

Click here.

  1. Object last(): This method will return last element in TreeSet if TreeSet is not null else it will throw NoSuchElementException.

In case if there is no element in the TreeSet you should output ‘-1’.

2 Likes