ArrayList reading: 10
嚜澧SE 143
Lecture 2
ArrayList
reading: 10.1
slides created by Marty Stepp
Exercise
? Write a program that reads a file and displays
the words of that file as a list.
每
每
每
每
First display all words.
Then display them with all plurals (ending in "s") capitalized.
Then display them in reverse order.
Then display them with all plural words removed.
? Should we solve this problem using an array?
每 Why or why not?
2
Naive solution
String[] allWords = new String[1000];
int wordCount = 0;
Scanner input = new Scanner(new File("data.txt"));
while (input.hasNext()) {
String word = input.next();
allWords[wordCount] = word;
wordCount++;
}
? Problem: You don't know how many words the file will have.
每 Hard to create an array of the appropriate size.
每 Later parts of the problem are more difficult to solve.
? Luckily, there are other ways to store data besides in an array.
3
Collections
? collection: an object that stores data; a.k.a. "data structure"
每 the objects stored are called elements
每 some collections maintain an ordering; some allow duplicates
每 typical operations: add, remove, clear, contains (search), size
每 examples found in the Java class libraries:
?ArrayList, LinkedList, HashMap, TreeSet, PriorityQueue
每 all collections are in the java.util package
import java.util.*;
4
Java collection framework
5
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- cs106a stanford handout 49 fall 2004 05 nick parlante
- chapter 19 java data structures
- ch7 list and iterator adts
- arrays and arraylists
- big o arraylist carnegie mellon university
- arrays stanford university
- arraylist reading 10
- arraylist in java
- java arraylist copyright © tutorialspoint
- building java programs chapter 10
Related searches
- grade 10 reading comprehension pdf
- 10 grade reading comprehension test
- grade 10 summer reading list
- chapter 10 photosynthesis reading guide
- ap biology reading guide chapter 10 photosynthesis
- 10 examples of reading skills
- 10 grade reading passages
- 10 grade reading comprehension printables
- grade 10 reading material
- reading comprehension worksheets for 10 grade
- 10 grade reading passage
- 10 grade reading words