Strings & Arrays CSCI-1302 Lakshmish Ramaswamy.

Slides:



Advertisements
Similar presentations
Intro to Scala Lists. Scala Lists are always immutable. This means that a list in Scala, once created, will remain the same.
Advertisements

List Implementations That Use Arrays
Computer Science 209 Software Development Equality and Comparisons.
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
Chapter 10 Review. Write a method that returns true is s1 and s2 end with the same character; otherwise return false. Sample Answer: public boolean lastChar(String.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
Introduction to Computers and Programming Strings Professor: Evan Korth New York University.
Arrays And ArrayLists - S. Kelly-Bootle
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Strings Representation and Manipulation. Objects Objects : Code entities uniting data and behavior – Built from primitive data types.
String Class in Java java.lang Class String java.lang.Object java.lang.String java.lang.Object We do not have to import the String class since it comes.
Strings.
From C++ to Java A whirlwind tour of Java for C++ programmers.
Some Standard Classes Goals The Object class The String class Wrapper classes The Math class Random Numbers.
Chapter 7: Characters, Strings, and the StringBuilder.
String String Builder. System.String string is the alias for System.String A string is an object of class string in the System namespace representing.
Data Structure and Algorithm: CIT231 Lecture 3: Arrays and ADT DeSiaMore DeSiaMorewww.desiamore.com/ifm1.
Chapter 2 Reference Types. Class : Point2D class Point2D { private double x,y; public Point2D(double xx,double yy) { x = xx ; y = yy ;} public void setX(double.
Chapter 5: Arrays in Java. The objectives of this chapter are:  1. To discuss the creation and use of Arrays.   2. To continue to use the String class.
ARRAYS Multidimensional realities Image courtesy of
Python Strings. String  A String is a sequence of characters  Access characters one at a time with a bracket operator and an offset index >>> fruit.
String. 2 Objectives Discuss string handling –System.String class –System.Text.StringBuilder class.
2 Arrays Array is a data structure that represents a collection of the same type of data. A "fixed length list".
Strings Chapter 7 CSCI CSCI 1302 – Strings2 Outline Introduction The String class –Constructing a String –Immutable and Canonical Strings –String.
The Methods and What You Need to Know for the AP Exam
AP Java Elevens Lab.
Java Arrays and ArrayLists COMP T1 #5
Computer Organization and Design Pointers, Arrays and Strings in C
You should understand everything on this slide
Strings, StringBuilder, and Character
Agenda Warmup Finish 2.4 Assignments
CS230 Tutorial Week 3.
String String Builder.
Programming Language Concepts (CIS 635)
Java Review: Reference Types
Primitive Types Vs. Reference Types, Strings, Enumerations
String Objects & its Methods
AP Java Unit 3 Strings & Arrays.
Chapter 7: Strings and Characters
MSIS 655 Advanced Business Applications Programming
Lists in Python.
CS Week 9 Jim Williams, PhD.
CS 200 Objects and ArrayList
ArrayLists.
Object Oriented Programming in java
CEV208 Computer Programming
Chapter 7 The Java Array Object © Rick Mercer.
Representation and Manipulation
CS 200 Arrays Jim Williams, PhD.
Python Primer 1: Types and Operators
ArrayLists 22-Feb-19.
Engineering Problem Solving with C++, Etter
Collections and iterators
Algorithms Lakshmish Ramaswamy.
Midterm Review CSE116A,B.
2009 Test Key.
Java: Variables, Input and Arrays
Subtype Substitution Principle
String Class.
Collections and iterators
In Java, strings are objects that belong to class java.lang.String .
Strings in Java Strings in Java are also a reference type.
Arrays.
FINAL EXAM Final Exam Tuesday, May 3: 1:00 - 3:00 PM (Phys 112)
COMPUTING.
Unit-2 Objects and Classes
String Methods Strings have actions known as method. We will review a few of the methods associated with strings that are a part of the built in Java.
Presentation transcript:

Strings & Arrays CSCI-1302 Lakshmish Ramaswamy

Organizational Matters Tutor hours Tuesday 6:00 – 7:00 PM; 306 GSRC Wednesday 6:00 – 7:40; 306 GSRC Office hours Will be emailed to you today Email list details

The “==“ Operator For reference types “==“ operator returns true only if They refer to the same object They are null Button a = new Button (“yes”); Button b = new Button (“yes”); Button c = a; c==a returns true where as b==a returns false Observe that semantics is consistent with reference concept

Strings Handled through the String reference type Permits operator overloading But not a primitive type Immutable – may not be changed after assignment Safe to use “=“ operator String empty = “”; String message = “Hello”; String repeat = message; Value of repeat can be changed by creating a new String object

String Concatenation Java does not allow operator overloading for reference types “+” is the only exception for strings + performs concatenations of lhs and rhs and returns reference to newly constructed String object Left associative “a” + “b” “b” + 5 5 + “c” “a” + 1 + 2 1 + 2 + “a”

String Comparisons <, >, <=, >= not defined == and != have semantics identical to reference types String lhs = new String(“CSCI 1302”); String rhs = “CSCI String(“CSCI 1302”); lhs == rhs returns false Equals method for testing equality lhs.equals(rhs) returns true compareTo for lexicographic comparison

String Methods String temp = “CSCI1302” int len = temp.length(); char ch = temp.charAt(2); String subtemp = temp.substring(1, 4)

More on Arrays Array of reference types Button [ ] arrayofButtons; arrayofButtons = new Button [5]; for (int i = 0; i < arrayofButtons.length(); i ++){ arrayofButtons[i] = new Button(); } arrayofButton[4].setLabel(“No”);

Dynamic Array Expansion int [] arr = new int [10]; ……. // But you actually need array of 12 integers int[ ] original = arr; arr = new int[12]; for(int i = 0; i < 10; i ++) arr[i] = original[i] original = null;

Illustration

ArrayList Built in functionality for dynamic sized arrays Size and capacity add method increases size by 1 & adds new item at the given position Expands the size if the capacity is reached get method for retrieving object at particular index

Multidimensional Arrays Multidimensional arrays are actually array of arrays int [ ][ ] x = new int [2][3]; \\ x is a an array of two arrays, x[0] and x[1] x.length(); \\ answer is 2 x[0].length(); \\ answer is 3; x[1].length(); \\ answer is 3;

Ragged Arrays