How is using a priority queue better than sorting an array?

if I sort the array it will take O(nlogn) time which is the same in creating a priority queue of n elements.
Then extracting k elements will take just O(k) time in an array but in priority queue that would take O(klogn). how is that better?

@shreyaanand2908 hey you are right. If we make a priority queue using a constructor, then formation of queue will take only O(N) (time to create a heap) after that each extraction will take log(n).
But here are we are doing n insertions it will be log(n) and it would not benefit us in terms of complexity.
Priority_queue provide better results when their are insertion and deletions going on, otherwise sorting is better, in most cases
If this resolves your doubt mark it as resolved.