Difference in LinkedList, queue vs list

前端 未结 3 1781
北荒
北荒 2020-12-13 13:58

What is the difference when creating these two objects

Queue test = new LinkedList();

and

List&         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 14:33

    In the both the cases, you are instantiating LinkedList.

    The difference is the types of the variables you use to refer to those instances.

    test is of type Queue and test2 is of type List. Depending on the type of variable, you only get to invoke the methods which are specified on that particular type. I think this what matters for your situation.

    Performance-wise, it's going to be the same, because the actual implementation that you are using in both the cases is same (LinkedList).

提交回复
热议问题