Declare and use List in java -
i touch java, found if need create new list
list<string> = new arraylist<string>(); but in homework, code following. in function postering, parameter list<integer> positions . can put 'arraylist' there? or usually put list there?
could explain in detailed way?
static class posting { int docid; list<integer> positions; public posting(int docid, list<integer> positions) { this.docid = docid; this.positions = positions; } }
list<integer> interface; arraylist<integer> class implementing interface. should use list<integer>, because lets caller change implementation - example, linkedlist<integer>.
this technique improving flexibility known programming interface. can read more advantages in answers question.
Comments
Post a Comment