Characters and Strings. Characters  New primitive char  char letter; letter = ‘a’; char letter2 = ‘C’;  Because computers can only represent numbers,

Slides:



Advertisements
Similar presentations
Java
Advertisements

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.
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
Programming 2 CS112- Lab 2 Java
0 PROGRAMMING IN HASKELL Chapter 5 - List Comprehensions.
CIS 234: Strings. What Is a String? series of characters enclosed in double quotes characters can include letters (lower case and upper case), digits,
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
23-Jun-15 Strings, Etc. Part I: String s. 2 About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects,
Strings, Etc. Part I: Strings. About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects, have a defined.
Introduction to Computers and Programming Strings Professor: Evan Korth New York University.
Lab session 3 and 4 Topics to be covered Escape sequences Escape sequences Variables /identifiers Variables /identifiers Constants Constants assignment.
28-Jun-15 String and StringBuilder Part I: String.
1 Strings and String Operations  What is a Strings?  Internal Representation of Strings  Getting Substrings from a String  Concatenating Strings 
Sanjay Goel, School of Business, University at Albany, SUNY 1 MSI 692: Special Topics in Information Technology Lecture 4: Strings & Arrays Sanjay Goel.
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.
Chars and strings Jordi Cortadella Department of Computer Science.
Strings.
Recursion A method is recursive if it makes a call to itself. A method is recursive if it makes a call to itself. For example: For example: public void.
From C++ to Java A whirlwind tour of Java for C++ programmers.
Characters. Character Data char data type – Represents one character – char literals indicated with ' '
Working with string In java Four classes are provided to work with String:1) String 2)String Buffer 3)String Tokenizer 4)String Builder Note: An object.
Examples of comparing strings. “ABC” = “ABC”? yes “ABC” = “ ABC”? No! note the space up front “ABC” = “abc” ? No! Totally different letters “ABC” = “ABCD”?
Characters, Strings, Reading Files CS2110, Week 2 Recitation.
Strings Chapter 7 CSCI CSCI 1302 – Strings2 String Comparisons Compare string contents with the equals(String s) method not == String s0 = “ Java”;
1 CS 177 Week 3 Recitation Slides Basic Math Operations, Booleans, and Character Operations.
PAGES Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.
Strings Chapter 7 CSCI CSCI 1302 – Strings2 Outline Introduction The String class –Constructing a String –Immutable and Canonical Strings –String.
Jaeki Song JAVA Lecture 07 String. Jaeki Song JAVA Outline String class String comparisons String conversions StringBuffer class StringTokenizer class.
String Class. Variable Holds a primitive value or a reference to an object. Holds a primitive value or a reference to an object. A reference lets us know.
Strings And other things. Strings Overview The String Class and its methods The char data type and Character class StringBuilder, StringTokenizer classes.
Strings Mr. Smith AP Computer Science A. What are Strings? Name some of the characteristics of strings: A string is a sequence of characters, such as.
Coding Bat: Ends in ly Given a string of even length, return a string made of the middle two chars, so the string "string" yields "ri". The string.
Repetition. Loops Allows the same set of instructions to be used over and over again Starts with the keyword loop and ends with end loop. This will create.
Chapter 3A Strings. Using Predefined Classes & Methods in a Program To use a method you must know: 1.Name of class containing method (Math) 2.Name of.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
int num = 22; if (num > 0) if (num % 5 == 0) System.out.println(num); else System.out.println(num + “ is negative”);
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
17-Feb-16 String and StringBuilder Part I: String.
UNDERSTANDING CLASSES CMSC 150: Lecture 17. String Literals  "Wilco"  String literal: a sequence of characters flanked by "  Want to operate on the.
CHAPTER 6 GC Strings. THE CLASS STRING  Contains operations to manipulate strings.  String:  Sequence of zero or more characters.  Enclosed.
Data Types References:  Data Type:  In computer science and computer programming, a data type or simply type is a.
Chapter 8: Loops, Arrays, Strings Loop statements –do –while –for Arrays –declaration, allocation, initialization, access –multi-dimensional –heterogeneous.
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.
Introduction to programming in java
String and StringBuffer classes
Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x2 | x  {1...5}} The set {1,4,9,16,25}
Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x2 | x  {1...5}} The set {1,4,9,16,25}
Chapter 6 GC 101 Strings.
Agenda Warmup Finish 2.4 Assignments
Programming in Java Text Books :
Text Pages
Java Strings Slides provided by the University of Washington Computer Science & Engineering department.
String and StringBuilder
CS 177 Week 3 Recitation Slides
Computers & Programming Languages
String and StringBuilder
String and StringBuilder
16 Strings.
Lecture 07 String Jaeki Song.
PROGRAMMING IN HASKELL
Recursion Problems.
String and StringBuilder
Text Pages
String methods 26-Apr-19.
String Methods.
Strings in Java.
More on iterations using
In Java, strings are objects that belong to class java.lang.String .
Presentation transcript:

Characters and Strings

Characters  New primitive char  char letter; letter = ‘a’; char letter2 = ‘C’;  Because computers can only represent numbers, Characters have ASCII values

Characters

 These values can be used in comparisons and in calculations:  char letter = ‘a’ + ‘c’;  char letter = (char) 70;  int valueOfX = (int) ‘X’;  ‘a’ < ‘b’

Strings  Strings are special objects  A String is a sequence of characters treated as a single value  String s = new String(“xyz”);  Its special because you can create them many different ways:  String s = “xyz”;  String s = inputBox.getString( );  s += “ABC”;

Strings  Strings are special objects  A String is a sequence of characters treated as a single value  String s = new String(“xyz”);  Its special because you can create them many different ways:  String s = new String(“xyz”);  String s = new String(inputBox.getString( ) );  s = new String( s + “ABC”);

Strings  Common String methods  length( ) - returns the length of the String  charAt(int i) – returns char at position I  CompareTo(String s) – 0 if equal, negative if this String is s  Substring(int beginIndex, int endIndex) – returns a new String  equals(String s) – true or false  equalsIgnoreCase(String s) – true or false  Know these!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Strings  Example: // count the number of letter a’s in a string int count = 0; char a = ‘a’; String s = inputBox.getString(); for (int i = 0; I < s.length( ); i++){ if (s.charAt( i ) == a) count++; }