Recitation 1 CS0445 Data Structures Mehmud Abliz.

Slides:



Advertisements
Similar presentations
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Advertisements

Sequence of characters Generalized form Expresses Pattern of strings in a Generalized notation.
Formal Language, chapter 4, slide 1Copyright © 2007 by Adam Webber Chapter Four: DFA Applications.
Chapter 6 The Collections API. Simple Container/ Iterator Simple Container Shape [] v = new Shape[10]; Simple Iterator For( int i=0 ; i< v.length ; i++)
More Java Syntax. Scanner class Revisited The Scanner class is a class in java.util, which allows the user to read values of various types. There are.
CSC 205 – Java Programming II Lecture 25 March 8, 2002.
Java Collections Framework COMP53 Oct 24, Collections Framework A unified architecture for representing and manipulating collections Allows collections.
1 L43 Collections (3). 2 OBJECTIVES  To use the collections framework interfaces to program with collections polymorphically.  To use iterators to “walk.
Algorithm Programming Containers in Java Bar-Ilan University תשס " ו by Moshe Fresko.
What Is a Collection?  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  Collections.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Collections The objectives of this chapter are: To outline the Collections infrastructure in Java To describe the various collection classes To discuss.
Java Review Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
The Collections Framework A Brief Introduction. Collections A collection is a structured group of objects –An array is a kind of collection –A Vector.
Dictionaries Chapter Chapter Contents Specifications for the ADT Dictionary A Java Interface Iterators Using the ADT Dictionary A Directory of Telephone.
2-1 CM0551 Week 3 The scanner class – file input A Spelling Checker Time and space requirements for various dictionary structures.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
CS Collection and Input/Output Classes CS 3331 Fall 2009.
Sets and Maps Part of the Collections Framework. The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection.
ADSA: Maps/ Advanced Data Structures and Algorithms Objectives – –examples of maps, and introduce map collection views Semester 2,
Java Programming: Advanced Topics 1 Collections and Wealth of Utilities.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Collections F The limitations of arrays F Java Collection Framework hierarchy  Use the Iterator interface to traverse a collection  Set interface, HashSet,
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Collections in Java. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection with no duplicates SortedSet.
1 Unit 10 - Data Structures Objectives 1. Describe the usage of data structures. 2. Develop simple data structures. 3. Apply Java collections. 4. Apply.
1 Sets and Maps Starring: keySet Co-Starring: Collections.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Exceptions. Exception Abnormal event occurring during program execution Examples –Manipulate nonexistent files FileReader in = new FileReader("mumbers.txt“);
1 Java: AP Curriculum Focus and Java Subset Alyce Brady.
Chapter 18 Java Collections Framework
1 TCSS 143, Autumn 2004 Lecture Notes Java Collection Framework: Maps and Sets.
1 Recitation 8. 2 Outline Goals of this recitation: 1.Learn about loading files 2.Learn about command line arguments 3.Review of Exceptions.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
1.0tCopyright © 1998 Purple Technology, Inc. 1 Java Collections Framework Authored by Alex Chaffee Copyright © 1998 Purple Technology, Inc. All rights.
Collection 105 Yola. To store data in RAM Variables (name all the types with their length) Arrays (one, two or more) Collections and Maps.
The Java Collections Framework Based on
Textbook: Data Structures and the Java Collections Framework 3rd Edition by William Collins William Collins.
3-February-2003cse Collections © 2003 University of Washington1 Java Collections CSE 403, Winter 2003 Software Engineering
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
Java 1.5 The New Java Mike Orsega Central Carolina CC.
1 Collections Framework A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain:
Sadegh Aliakbary Sharif University of Technology Fall 2012.
SETS AND MAPS Collections of Data. Advanced Data Structures Often referred to as the Java Collections Framework…. Set and map data types Hash tables Binary.
Collections Mrs. C. Furman April 21, Collection Classes ArrayList and LinkedList implements List HashSet implements Set TreeSet implements SortedSet.
Recitation 5 Enums and The Java Collections classes/interfaces 1.
1 / 65 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 12 Programming Fundamentals using Java 1.
Sets and Maps Part of the Collections Framework. 2 The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection.
CS1020 Data Structures and Algorithms I Lecture Note #6 Vector and ArrayList.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 18 List ADT Animated Version.
4-Mar-16 Introduction to Collections. Revision questions True false questions 0 for False 1 for True Please do not answer anything other than the above.
Programming Fundamentals 2: Libraries/ F II Objectives – –utilize some useful Java libraries e.g. String, Scanner, HashMap, and Random.
Hashing By Emily Nelson. The Official Definition Using a hash function to turn some kind of data in relatively small integers or Strings The “hash code”
Java Collection Classes Com379PT
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
1 Text File Input and Output. Objectives You will be able to Write text files from your Java programs. Read text files in your Java programs. 2.
Click to edit Master text styles Stacks Data Structure.
For Friday Finish reading chapter 9 WebCT quiz 17.
Java Collections CHAPTER 3-February-2003
Testing and Exceptions
File I/O & collection frame work
TCSS 143, Autumn 2004 Lecture Notes
Containers ב Java אליהו חלסצ'י תכנות מתקדם תרגול מספר 3
Introduction to Classes and Methods
L5. Necessary Java Programming Techniques
Hashing in java.util
Recitation 2 CS0445 Data Structures
Presentation transcript:

Recitation 1 CS0445 Data Structures Mehmud Abliz

Outline Discuss the following features of JAVA –Scanner (reading lines of input) –String Manipulation –Linked List –Hash Map

Scanner class A simple text scanner which can parse primitive types and strings. A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods.

Example(1) this code allows a user to read a number from System.in. Scanner sc = new Scanner(System.in); int i = sc.nextInt();

Example(2) import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class TextScanner { private static void readFile(String fileName) { try { File file = new File(fileName); Scanner scanner = new Scanner(file); while (scanner.hasNext()) { System.out.println(scanner.next()); } scanner.close(); } catch (FileNotFoundException e) { e.printStackTrace(); }

Example(2) Cont. public static void main(String[] args) { if (args.length != 1) { System.err.println("usage: java TextScanner1" + "file location"); System.exit(0); } readFile(args[0]); }

String manipulation Some examples of string usage: System.out.println("abc"); String cde = "cde"; System.out.println("abc" + cde); String c = "abc".substring(2,3); String d = cde.substring(1, 2);

String manipulation functions length(): returns the length of this string. charAt() : returns the character at the specified index. An index ranges from 0 to length() - 1. indexOf(): returns the index of the first occurrence of the specified character within this string. substring(): returns a new string that is a substring of this string.

Linked List LinkedList class: –can be used as a stack, queue, or double- ended queue.

Linked List – some methods add(int, Object): inserts the specified element at the specified position in this list. add(Object): appends the specified element to the end of this list. contains(Object): returns true if this list contains the specified element. get(int): returns the element at the specified position in this list.

Linked List – some methods size(): returns the number of elements in this list. isEmpty(): returns true if this list contains no elements.

Example(3) class LinkedListExample { public static void main(String[] args) throws Exception { LinkedList list = new LinkedList(); list.add("Hello"); list.add("world"); list.add(0,"there"); list.add(0,"there1"); list.add(1,"here"); ListIterator itt = list.listIterator(); while (itt.hasNext()) { String line = (String) itt.next(); System.out.println(line); } } // end main }

HashMap HashMap is hash table based implementation of the Map interface. The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. This class makes no guarantees as to the order of the map.

HashMap – Some methods put(Object, Object): associates the specified value with the specified key in this map. get(Object key): returns the value to which the specified key is mapped in this identity hash map, or null if the map contains no mapping for this key.

HashMap – Some methods containsKey(Object key): returns true if this map contains a mapping for the specified key. containsValue(Object value): returns true if this map maps one or more keys to the specified value.

HashMap – Some methods keySet(): returns a set view of the keys contained in this map. Returned object is a Set object, and can be usedconverted to an array with toArray(). values(): returns a collection view of the values contained in this map.

HashMap Example // Create a new HashMap HashMap hash = new HashMap(); // Add values to the created HashMap hash.put("one", new Integer(1)); hash.put("two", new Integer(2)); hash.put("three", new Integer(3));