1 / 7

Array og ArrayList

Array og ArrayList. Et slideshow. Som er sødt. Hvordan virker ArrayList ?. ArrayList<Type > NAVN = new ArrayList<type >(); NAVN.add (”Værdi”); NAVN.add ( index , ”værdi”) NAVN.set ( index , ” value ”) NAVN.get ( index ); NAVN.remove ( index ); NAVN.size (); NAVN.clear ();.

leola
Télécharger la présentation

Array og ArrayList

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Array og ArrayList Et slideshow. Som er sødt.

  2. Hvordan virker ArrayList? • ArrayList<Type> NAVN = new ArrayList<type>(); • NAVN.add(”Værdi”); • NAVN.add(index, ”værdi”) • NAVN.set(index, ”value”) • NAVN.get(index); • NAVN.remove(index); • NAVN.size(); • NAVN.clear();

  3. Hvordan virker ArrayList? • NAVN.contains(”værdi”); • NAVN.indexOf(”værdi”); • NAVN.lastIndexOf(”værdi);

  4. Hvordan virker ArrayList? • Collections.sort(NAVN);

  5. Fordele ved Arraylist • Du skal ikke definere længden • Din ArrayList er ikke for lang eller for kort. • Der kan tilføjes uden at holde styr på længden

  6. Hvordan bruges ArrayList? • import java.util.*; • public class test • { • public staticvoidmain(String [] args) • { • ArrayList<String> Bien = new ArrayList<String>(); • Bien.add("oejne"); • Bien.add("vinger"); • Bien.add("ben"); • Bien.add("stikkepen"); • for ( int i=0; i<Bien.size(); i++) • { • System.out.println("Bien har " + Bien.get(i)); • } • } • }

  7. ArrayList og Arrays forskelle • Array har begrænset antal index’s/længde. • ArrayList har dynamisk længde der passer til de elementer den skal gemme. • Array er nemmere at benytte til flere dimensioner. • ArrayList har dejlige service funktioner. • Array kan kun gemme primitive datatyper eller objekter. • ArrayList gemmer kun objekter, ikke primitive datatyper.

More Related