New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

Week 5 Notes

by: Taylor Kahl

Week 5 Notes CSC 2310

Taylor Kahl
GPA 4.21

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Notes from lectures on Monday Feb 8 and Wednesday Feb 10
Princliples of Computer Programming
Kebina Manandhar
Class Notes
25 ?




Popular in Princliples of Computer Programming

Popular in ComputerScienence

This 4 page Class Notes was uploaded by Taylor Kahl on Sunday February 14, 2016. The Class Notes belongs to CSC 2310 at Georgia State University taught by Kebina Manandhar in Winter 2016. Since its upload, it has received 29 views. For similar materials see Princliples of Computer Programming in ComputerScienence at Georgia State University.

Similar to CSC 2310 at GSU

Popular in ComputerScienence


Reviews for Week 5 Notes


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 02/14/16
Ch. 10: ArrayLists  ArrayLists are more flexible than arrays; you can add or remove elements  Stores a list of elements of a specified type, such as a list of Strings  Part of the java.util package o have to import this in your code to make and use ArrayLists import java.util.ArrayList;  Syntax for constructing a new ArrayList: ArrayList<type> name = new ArrayList<type>(); o Example: an ArrayList of Strings named list: ArrayList<String> list = new ArrayList<String>(); o the ArrayList is initially empty  Adding elements to list: o add(value) method – automatically adds elements to the end of the array list.add(“Computer Science”); list.add(“Discrete Math”);  Printing – ArrayLists already have a toString method so printing is simple; just use the variable name System.out.print(“list: ” + list); o Output: list = [Computer Science, Discrete Math]  Element indexes: o ArrayLists use zero-based indexing, like String and Arrays o 1 element has index 0 o last element has index = length – 1  for my list with length 2, the final index is 1 Element Computer Science Discrete Math Index 0 1  Adding elements at specific indexes: o add(index, value) list.add(1, “History”); //puts “History” at index 1 o Now list looks like this: [Computer Science, History, Discrete Math]  Removing elements at specific indexes: o remove(index) list.remove(0); //removes the element at index 0 o Now list looks like this: [History, Discrete Math] ***When adding and removing elements, the ArrayList will change size and automatically shift the other elements as needed  Other ArrayList methods: clear() removes all elements get(index) gets value at that index size() returns current # of elements set(index, value) replaces the element at that index with the new value contains(value) returns true or false, whether the ArrayList contains that value indexOf(value) returns the index of the value’s first occurrence; -1 if it doesn’t find it lastIndexOf(value) returns index of the last occurrence of a value startsWith(value)/endsWith(value) whether an ArrayList starts/ends with a value  an ArrayList can be used as a parameter or a return type  An ArrayList cannot be of a primitive type; must be an object o can use primitive types using wrapper classes: Primitive type Wrapper type int Integer double Double char Character boolean Boolean o so to make an ArrayList of a primitive type, you have to use its wrapper class  ArrayList<Integer> list = new ArrayList<Integer>(); Example code using ArrayLists: a program to print an ArrayList of Strings and then reverse its order import java.util.ArrayList; public class ArrayListString { public static void main(String[] args) { ArrayList<String> allWords = new ArrayList<String>(); allWords.add("a"); allWords.add("b"); allWords.add("c"); allWords.add("d"); System.out.println(allWords); st for (int i=0; i<allWords.size()/2; i++) { //to switch the 1 half of the elements with the 2 ndhalf String temporary = allWords.get(i); //a temporary String allWords.set(i,allWords.get(allWords.size()-1-i)); //1 index replaced by the last allWords.set(allWords.size()-1-i,temporary); //last index gets the temporary String } //and so on System.out.println(allWords); } } Output: [a, b, c, d] [d, c, b, a] Example: An ArrayList of integers. Then remove the odd numbers. import java.util.ArrayList; public class ArrayListNumbers { public static void main(String[] args) { ArrayList<Integer> numbers = new ArrayList<Integer>(); //wrapper class for int numbers.add(1); numbers.add(2); numbers.add(3); numbers.add(4); System.out.println(numbers); for (int i=0; i<numbers.size(); i++) { if (numbers.get(i)%2==1) { numbers.remove(i); i--; //necessary because removing an element will decrease the list’s size by 1 } } System.out.println(numbers); } } Output: [1, 2, 3, 4] [2, 4]


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Jennifer McGill UCSF Med School

"Selling my MCAT study guides and notes has been a great source of side revenue while I'm in school. Some months I'm making over $500! Plus, it makes me happy knowing that I'm helping future med students with their MCAT."

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"


"Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.