Lecture 14 March 23, 2000. Exam Results Class Average was 69.4 –Median was 72.5 (which means there were some very low grades) Questions 31, 32, and 33.

Slides:



Advertisements
Similar presentations
Java
Advertisements

1 StringBuffer & StringTokenizer Classes Chapter 5 - Other String Classes.
String Pemrograman Berbasis Obyek Oleh Tita Karlita.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 9 Strings and Text I/O.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
©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.
Fundamental Programming Structures in Java: Strings.
©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.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 11 – Strings and Characters Outline 11.1 Introduction 11.2 Fundamentals of Characters and Strings.
Session 5 java.lang package Using array java.io package: StringTokenizer, ArrayList, Vector Using Generic.
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.
BPJ444: Business Programming Using Java – String Handling Tim McKenna
The Scala API Application Programmer’s Interface.
The java.lang Package chapter 8 Java Certification Study Group February 2, 1998 Seth Ladd.
Chapter 7 Strings  Use the String class to process fixed strings.  Use the StringBuffer class to process flexible strings.  Use the StringTokenizer.
String Manipulation Chapter 15 This chapter explains the String facilities. You have already seen some of the main methods of the String class.
1 String Class The primitive data types provide only the char for dealing with alpha-numeric 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.
Chapter 7: Characters, Strings, and the StringBuilder.
Geoff Holmes Date Math Weighted Distr Strings String methods Tokenizers System Examples Utility Classes (Chapter 17) import java.util.*;
Jaeki Song JAVA Lecture 07 String. Jaeki Song JAVA Outline String class String comparisons String conversions StringBuffer class StringTokenizer class.
Strings and Text File I/O (and Exception Handling) Corresponds with Chapters 8 and 17.
1 The String Class F Constructing a String: F Obtaining String length and Retrieving Individual Characters in a string F String Concatenation (concat)
String Definition A String is a set of characters that behaves as a single unit. The characters in a String include upper-case and lower-case letters,
String Object String is a sequence of characters. Unlike many other programming languages that implements string as character arrays, Java implements strings.
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 Definition A string is a set of characters that behaves as a single unit. The characters in a string include upper-case and lower- case letters,
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:
The String class is defined in the java.lang package
String and StringBuffer classes
JAVA API Strings, I/O, Formatting and Parsing
Basic Utility Classes U Abd. Rohim, MT mailto:
Object-Oriented Java Programming
Strings, Characters and Regular Expressions
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
EKT 472: Object Oriented Programming
String and String Buffers
Primitive Types Vs. Reference Types, Strings, Enumerations
Modern Programming Tools And Techniques-I Lecture 11: String Handling
F4105 JAVA PROGRAMMING F4105 Java Programming
Chapter 7: Strings and Characters
Object Oriented Programming
MSIS 655 Advanced Business Applications Programming
Part a: Fundamentals & Class String
String Handling String, StringBuffer, StringBuilder
Java – String Handling.
Lecture 07 String Jaeki Song.
CS2011 Introduction to Programming I Strings
Visual Programming COMP-315
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:

Lecture 14 March 23, 2000

Exam Results Class Average was 69.4 –Median was 72.5 (which means there were some very low grades) Questions 31, 32, and 33 counted 5, 15, and 20 points respectively. Short answers 2 each. Question 31 result = theString.compareTo( “hello” );

Question 32 public void printAllCards() { for ( int v = 0; v < value.length; v++ ) { for ( int s = 0; s < suit.length; s++) { System.out.println( value[v] + “ of “ + suit[s] ); }

// Question_33.java import java.io.*; import java.util.*; public class Question_33 { public static void main( String[] argv ) { if ( argv.length != 1 ) { System.err.println( "You must give exactly one file name." ); System.exit( 1 ); } int count = 0; try { BufferedReader br = new BufferedReader( new FileReader(argv[0]) ); String inBuf; StringTokenizer st; while( null != (inBuf = br.readLine()) ) { st = new StringTokenizer( inBuf, ); while ( st.hasMoreTokens() ) { System.out.println( st.nextToken() ); count++; } catch ( IOException ioe ) { System.err.println( argv[0] + ": " + ioe.getMessage() ); System.exit( 1 ); } System.out.println( "There were " + count + " words." ); System.exit( 0 ); }

Class java.lang.String (Chapter 10) Nine Constructors (see textbook) Comparisons –compareTo(), compareToIgnoreCase(), equals(), equalsIgnoreCase(), endsWith(), startsWith(), regionMatches() –equal() vs. = = [ StringCompare.java ]StringCompare.java Generators –substring(), toLowerCase(), toUpperCase(), trim(), replace(), concat(), toString() Converters: valueOf() [9 of them; see page 475] Utilities –charAt(), getBytes(), getChars(), indexOf(), hashCode(), lastIndexOf(), length()

Class StringBuffer Big speed advantage compared to class String Three Constructors Utilities –Length(), capacity(), setLength(), ensureCapacity() Getters –charAt(), getChars(), substring() Manipulators –reverse(), setCharAt(), insert() (10 of them), append() (10 of them), replace()

Class StringTokenizer Already covered in Exercises. See textbook for details.

Exercise 6 Write a Java application named Grep that takes any number of command line arguments. –If the first argument is “-i” do case insensitive comparisons. – The next argument is a “search string” –The next argument(s) are file names. Print each line in each file that contains the search string. –If there are multiple files, print the filename before each line. Will be done in two stages, 6a and 6b.