Javada LinkedList doubly linked list dan foydalanib elementlarni yig’adi. U AbstractList clasidan meros(extends) oladi va List va Deque interface lardan implement oladi ArrayListdan farqlaridan ham biri Deque dan implement olishidur. LinkedList classda boshqarish jarayonlari tez sodir bo’ladi chunkiy LinkedList da elementlarni ko’chirib o’tkazilmaydi LinkedList da ham ma’lumotlar bilan ishlash ArrayList bilan deyarli birxil amalga oshiriladi.
import java.util.*;
public class TestCollection7{
public static void main(String args[]){
LinkedList al=new LinkedList();
al.add("Zafar");
al.add("Aziz");
al.add("Jalol");
al.add("Zafar");
Iterator itr=al.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
}
}
LinkedListda gi ma’lumotlarni ArrayListga qo’shib qo’yishga misol
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class ConvertExample {
public static void main(String[] args) {
LinkedList linkedlist = new LinkedList();
linkedlist.add("Zafar");
linkedlist.add("Aziz");
linkedlist.add("Jalol");
linkedlist.add("Fayzullo");
List list = new ArrayList(linkedlist);
for (String str : list){
System.out.println(str);
}
}
}
Do'stlaringiz bilan baham: |