7-ma’ruza Javada massivlar
ArrayList da saralash usullari
Download 45.28 Kb.
|
10-maruza
- Bu sahifa navigatsiya:
- Integer sortga misol
ArrayList da saralash usullari1. Yuqoridan quyiga qarab 2. Quyidan yuqoriga qarab Yuqoridan quyiga qarab saralashga misollar Sting turdagi ArrayList yaratamiz va undagi ma'lumotlarni saralaymiz import java.util.*; public class Details { public static void main(String args[]) { ArrayList listofcountries.add("India"); listofcountries.add("US"); listofcountries.add("China"); listofcountries.add("Uzbekistan"); /* Saralanmagan ro'yhat */ System.out.println("Saralashdan oldin:"); for(String counter: listofcountries) { System.out.println(counter); } /* Saralash ifodasi */ Collections.sort(listofcountries); /* Saralangan ro'yhat */ System.out.println("Saralashdan keyin:"); for(String counter: listofcountries) { System.out.println(counter); } } } Ekranda Saralashdan oldin: India US China Uzbekistan Saralashdan keyin: China India US uzbekistan Integer sortga misol:import java.util.*; public class ArrayListOfInteger { public static void main(String args[]){ ArrayList arraylist.add(11); arraylist.add(2); arraylist.add(7); arraylist.add(3); /* ArrayList saralashdan avval */ System.out.println("Saralashdan oldin:"); for(int counter: arraylist) { System.out.println(counter); } /* Collections.sort 'dan foydalanib arrayList ni saralash*/ Collections.sort(arraylist); /* ArrayList saralashdan keyin*/ System.out.println("Saralashdan keyin:"); Download 45.28 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling