import java.util.ArrayList; import java.util.Collections; class Hovedprogram { public static void main(String[] args) { // compareTo Bok bok1 = new Bok("Kurt blir grusom 1", 1800); Bok bok2 = new Bok("Kurt blir grusom 2", 2000); Bok bok3 = new Bok("Kurt blir grusom 3", 1989); Bok bok4 = new Bok("Kurt blir grusom 4", 2012); Bok bok5 = new Bok("Kurt blir grusom 5", 2020); //System.out.println(bok1.compareTo(bok2)); ArrayList liste = new ArrayList(); liste.add(bok1); liste.add(bok2); liste.add(bok3); liste.add(bok4); liste.add(bok5); System.out.println("Før sortering"); for (Bok b : liste){ System.out.println(b); } Collections.sort(liste); System.out.println("\nEtter sortering"); for (Bok b : liste){ System.out.println(b); } System.out.println("1".compareTo("e")); // Lenkeliste MinLenkeliste l = new MinLenkeliste(); l.settInn("String 1"); l.settInn("String 2"); l.settInn("String 3"); //l.print(); // Innkapsling ArrayList liste = new ArrayList(); liste.add(new Integer(2)); liste.add(5); liste.add(7); for (int t : liste){ System.out.println(t); } } } class Tall { int tall; public Tall(int tall){ this.tall = tall; } public String toString(){ //return Integer.toString(tall); return "" + tall; } }