Delsa Delsa - 10 days ago 6
Java Question

How can I add a new method to a linked list instance?

I have declared a

class
called
ResultClass
and I have made a
linkedList
from that

private LinkedList<ResultClass> listOfResults;


Now I want to add a new method called
getSample(Double d)
that I wish to use that like
listOfResults.getSample(0.5)
. How can I declare a method like that in Java?

Answer

You'd have to create a new class for this. E.g.:

public class SamplingLinkedList<T> extends LinkedList<T> {
   public List<T> getSample(double d) {
       return // something;
   }
}