Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to copy a linked list to another in java

// Java code to illustrate clone() method
import java.io.*;
import java.util.LinkedList;
  
public class LinkedListDemo {
      
    public static void main(String args[]) {
      
        // Creating an empty LinkedList
        LinkedList<String> list = new LinkedList<String>();
      
        // Use add() method to add elements in the list
        list.add("Geeks");
        list.add("for");
        list.add("Geeks");
        list.add("10");
        list.add("20");
      
        // Displaying the list
        System.out.println("First LinkedList:" + list);
      
        // Creating another linked list and copying
        LinkedList sec_list = new LinkedList();
        sec_list = (LinkedList) list.clone();
          
        // Displaying the other linked list
        System.out.println("Second LinkedList is:" + sec_list);
    }
}
/*Output:
First LinkedList:[Geeks, for, Geeks, 10, 20]
Second LinkedList is:[Geeks, for, Geeks, 10, 20]*/
Comment

PREVIOUS NEXT
Code Example
Java :: how to find all apps on android device using java 
Java :: A method that returns a stream of JUnit Arguments 
Java :: how to get single value from input string in java 
Java :: exception in thread "main" java.lang.arrayindexoutofboundsexception: 10 
Java :: seekbar thumb position 
Java :: how to add 0 in left padding using regular expression java 
Java :: java clump list 
Java :: getdatetimeinstance android 
Java :: Path to home directory java 
Java :: arrays in constructor java 
Java :: java oop design patterns 
Java :: Original authors: Talmon Marco, Igor Magazinnik Programming languages: Java, C, Python, C , Qt, Objective-C 
Java :: how to split each string of a line 
Java :: codding loop 
Java :: how to convert string to int android studio kotlin 
Java :: Accept Integer only in if else statement 
Java :: how to create a udp protocol for transfer a big quantity of files java 
Java :: convert from java to kotlin online 
Java :: java supress unchecked 
Java :: metodi di javascritp 
Java :: regex pattern for car plates 
Java :: how to create space between element in vbox in javafx 
Java :: Java Documenting assumptions 
Java :: cannot find symbol final TextView textView = root.findViewById(R.id.text_home); 
Java :: Java Creating ArrayDeque 
Java :: java gson get object without class 
Java :: least significant bit java 
Java :: java for loop example 
Java :: This version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot open this project, please retry with version 2020.3.1 or newer. 
Java :: Join Two Java Strings 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =