MSIS 655 Advanced Business Applications Programming

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Advertisements

Strings in Java 1. strings in java are handled by two classes String &
Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
1 Working with String Duo Wei CS110A_ Empty Strings An empty string has no characters; its length is 0. Not to be confused with an uninitialized.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 8 Strings.
Java Programming Strings Chapter 7.
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.
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 9 Characters and Strings (sections ,
CSM-Java Programming-I Spring,2005 String Handling Lesson - 6.
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,
Fundamental Programming Structures in Java: Strings.
Strings, Etc. Part I: Strings. About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects, have a defined.
28-Jun-15 String and StringBuilder Part I: String.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 9 Characters and Strings (sections ,
 Pearson Education, Inc. All rights reserved Strings, Characters and Regular Expressions.
Strings Edward J. Biebel. Strings Strings are fundamental part of all computing languages. At the basic level, they are just a data structure that can.
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
Characters, String and Regular expressions. Characters char data type is used to represent a single character. Characters are stored in a computer memory.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Lecture 14 March 23, Exam Results Class Average was 69.4 –Median was 72.5 (which means there were some very low grades) Questions 31, 32, and 33.
Chapter 7 Strings  Use the String class to process fixed strings.  Use the StringBuffer class to process flexible strings.  Use the StringTokenizer.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
Chapter 7: Characters, Strings, and the StringBuilder.
CHAPTER 9 Text Processing and More about Wrapper Classes Copyright © 2016 Pearson Education, Inc., Hoboken NJ.
1 Textual Data Many computer applications manipulate textual data word processors web browsers online dictionaries.
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.
G51PR1 Introduction to Programming I University of Nottingham Unit 8 : Strings.
1 Java Strings Dr. Randy M. Kaplan. 2 Strings – 1 Characters are a fundamental data type in Java It is common to assemble characters into units called.
Strings and Related Classes String and character processing Class java.lang.String Class java.lang.StringBuffer Class java.lang.Character Class java.util.StringTokenizer.
String class. Method concat Create string object –> String st1, st2; Input character to string object –> st1=br.readLine(); st2= br.readLine(); Use method.
Java String 1. String String is basically an object that represents sequence of char values. An array of characters works same as java string. For example:
17-Feb-16 String and StringBuilder Part I: String.
Strings A string is a sequence of characters that is treated as a single value. Strings are objects. We have been using strings all along. For example,
String and StringBuffer classes
Object-Oriented Java Programming
Strings, Characters and Regular Expressions
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
EKT 472: Object Oriented Programming
University of Central Florida COP 3330 Object Oriented Programming
String and String Buffers
String Handling in JAVA
Primitive Types Vs. Reference Types, Strings, Enumerations
Modern Programming Tools And Techniques-I Lecture 11: String Handling
String and StringBuilder
Chapter 7: Strings and Characters
Object Oriented Programming
Advanced String handling
Part a: Fundamentals & Class String
String and StringBuilder
Chapter 9 Strings and Text I/O
String and StringBuilder
Java – String Handling.
Lecture 07 String Jaeki Song.
String and StringBuilder
CS2011 Introduction to Programming I Strings
String methods 26-Apr-19.
Strings in Java.
Dr. Sampath Jayarathna Cal Poly Pomona
Chapter 7 Strings Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. Use the String class to process fixed.
Object-Oriented Java Programming
In Java, strings are objects that belong to class java.lang.String .
Presentation transcript:

MSIS 655 Advanced Business Applications Programming Week 8 Strings and Characters (Ch. 29) In this chapter you will learn: To create and manipulate immutable character string objects of class String. To create and manipulates mutable character string objects of class StringBuffer. To create and manipulate objects of class Character. To use a StringTokenizer object to break a String object into tokens. To use regular expressions to validate String data entered into an application. 11/18/2018 8.1

Introduction String and character processing String Class java.lang.String Class java.lang.StringBuffer Class java.lang.Character Class java.util.StringTokenizer String Series of characters treated as single unit May include letters, digits, special characters. Object of class String String literals 1Java treats all string literals with the same contents as a single String object that has many references to it. This conserves memory. 11/18/2018

String Constructors Fig. 29.1 demonstrates four constructors No-argument constructor One-argument constructor A String object A char array Three-argument constructor An integer specifies the starting position An integer specifies the number of characters to access 11/18/2018

String Methods (Fig. 29.2) Method length Method charAt Method getChars Determine the length of a String Like arrays, Strings always “know” their size Unlike array, Strings do not have length instance variable Method charAt Get character at specific location in String Method getChars Get entire set of characters in String Method (void) getChars (int srcBegin, int srcEnd, char[] dst, int dstBegin)    Copies characters from this string into the destination character array. ex: String s1 = “hello there”; s1.getChars( 0, 5, charArray, 0); => charArray = {“h”, “e”, “l”, “l”, “o”} 11/18/2018

Comparing Strings (Fig. 29.3) Comparing String objects Method equals Method equalsIgnoreCase Method compareTo Method regionMatches Comparing references with == can lead to logic errors, because == compares the references to determine whether they refer to the same object, not whether two objects have the same contents. When two identical (but separate) objects are compared with ==, the result will be false. When comparing objects to determine whether they have the same contents, use method equals. - Method (boolean) regionMatches (int toffset, String other, int ooffset, int len) Tests if two string regions are equal. A substring of this String object is compared to a substring of the argument other. The result is true if these substrings represent identical character sequences. The substring of this String object to be compared begins at index toffset and has length len. The substring of other to be compared begins at index ooffset and has length len. The result is false if and only if at least one of the following is true: toffset is negative. ooffset is negative. toffset+len is greater than the length of this String object. ooffset+len is greater than the length of the other argument. There is some nonnegative integer k less than len such that: this.charAt(toffset+k) != other.charAt(ooffset+k) 11/18/2018

Miscellaneous String Methods Methods startsWith / endsWith Methods indexOf / lastIndexOf Method substring Method concat Methods replace / toUpperCase / toLowerCase / trim Method valueOf startsWith(String prefix) returns true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise. lastIndexOf(String str): if the string argument occurs one or more times as a substring within this object, then the index of the first character of the last such substring is returned. If it does not occur as a substring, -1 is returned. trim() returns a copy of the string, with leading and trailing whitespace omitted. "to".concat("get").concat("her") returns "together" 11/18/2018

Class StringBuffer Class StringBuffer When String object is created, its contents cannot change Used for creating and manipulating dynamic string data i.e., modifiable Strings Can store characters based on capacity Capacity expands dynamically to handle additional characters Uses operators + and += for String concatenation In programs that frequently perform string concatenation, or other string modifications, it is more efficient to implement the modifications with class StringBuffer (covered in Section 29.4). 11/18/2018

Class Character Treat primitive variables as objects Type wrapper classes Boolean Character Double Float Byte Short Integer Long 11/18/2018

Class StringTokenizer Partition String into individual substrings Use delimiter Typically whitespace characters (space, tab, newline, etc) Java offers java.util.StringTokenizer 11/18/2018

Lab activities (Week 8) Exercises (pp. 1392-93) 29.5, 29.7, 29.8, Advanced: 29.19 11/18/2018