Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,971 questions

51,913 answers

573 users

How to shuffle a LinkedList in Java

1 Answer

0 votes
import java.util.LinkedList;
import java.util.Collections;

public class MyClass {
    public static void main(String args[]) {
        LinkedList<Integer> ll = new LinkedList<Integer>();
        
        ll.add(1);
        ll.add(2);
        ll.add(3);
        ll.add(4);
        ll.add(5);
        
        System.out.println(ll);
        
        Collections.shuffle(ll);
        
        System.out.println(ll);
    }
}
  
  
  
/*
run:
  
[1, 2, 3, 4, 5]
[5, 1, 2, 4, 3]
  
*/  

 



answered Mar 29, 2021 by avibootz

Related questions

2 answers 143 views
143 views asked Nov 8, 2023 by avibootz
2 answers 109 views
109 views asked Mar 25, 2023 by avibootz
2 answers 140 views
140 views asked Oct 30, 2021 by avibootz
1 answer 165 views
165 views asked Mar 28, 2021 by avibootz
1 answer 255 views
255 views asked Mar 15, 2021 by avibootz
1 answer 164 views
...