GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/java-list-map/src/main/java/com/hmkcode/ListApp.java at master · ring04w/Java Expand file tree/ Copy pathListApp.javaMore file actions 68 lines (49 loc) · 1.72 KB / Copy pathListApp.javaFile metadata and controls68 lines (49 loc) · 1.72 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 package com.hmkcode; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.List; import com.hmkcode.vo.Person; public class ListApp { public static void main( String[] args ) { // ( 1 ) List // A. Initiate List<Person> arrayList = new ArrayList<Person>(); List<Person> linkedList = new LinkedList<Person>(); // B. Populate for(Person person:getPersons()){ arrayList.add(person); linkedList.add(person); } // --> print System.out.println("--------- Print All -------------"); System.out.println("ArrayList: "+arrayList); System.out.println("LinkedList: "+linkedList); // C. Iterate System.out.println("--------- Print Iterate by index -------------"); for(int i = 0; i < linkedList.size(); i++){ System.out.println("LinkedList[ "+i+" ]"+linkedList.get(i)); } System.out.println("--------- Print Iterate by for each -------------"); //this is an efficient way to iterate for(Person person:linkedList){ System.out.println("LinkedList: "+person); } // D. Sort Collections.sort(linkedList); // --> print System.out.println("--------- Print Sorted List -------------"); System.out.println("Sorted LinkedList: "+linkedList); } private static Person[] getPersons(){ Person[] persons = new Person[5]; persons[0] = new Person("Brit", 29); persons[1] = new Person("John", 32); persons[2] = new Person("Jack", 27); persons[3] = new Person("Jenifer", 24); persons[4] = new Person("Brit", 37); return persons; } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |