Convert a Queue to List

后端 未结 6 1155
Happy的楠姐
Happy的楠姐 2020-12-31 01:29

What is the fastest way to convert a Queue into a List while keeping the Queue order?

6条回答
  •  失恋的感觉
    2020-12-31 01:59

    Pass Queue To ArrayList Constructor

    The easiest way to just create a ArrayList and pass your Queue as an argument in the constructor of ArrayList that takes a Collection. A Queue is a Collection, so that works.

    This is the easiest way and I believe fastest way too.

    List list = new ArrayList<>( myQueue );
    

提交回复
热议问题