dvas0004 / NerdNotes

A collection of notes: things I'd like to remember while reading technical articles, technical questions I couldn't answer, and so on.
12 stars 0 forks source link

Java collections 'remove' method #77

Open dvas0004 opened 5 years ago

dvas0004 commented 5 years ago

Java Collections all have the remove method. The remove method actually takes two types of arguments:

  1. An object. Java will remove a matching object from the collection
  2. A primitive int. Java will remove the object in the collection at the index position specified by the int

For example:

List<String> demo = new ArrayList<>();
demo.add('demo1');
demo.add('demo2');

//example of (1)
demo.remove('demo2');

//example of (2)
demo.remove(0)