String Methods.

Slides:



Advertisements
Similar presentations
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Advertisements

Strings Testing for equality with strings.
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.
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.
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.
Programming 2 CS112- Lab 2 Java
J.43 ARRAYS  A Java array is an Object that holds an ordered collection of elements.  Components of an array can be primitive types or may reference.
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,
Strings, Etc. Part I: Strings. About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects, have a defined.
String StringBuffer. class StringExample { public static void main (String[] args) { String str1 = "Seize the day"; String str2 = new String(); String.
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.
COMP 110 Introduction to Programming Mr. Joshua Stough September 10, 2007.
1 Strings and String Operations  What is a Strings?  Internal Representation of Strings  Getting Substrings from a String  Concatenating Strings 
Week #2 Java Programming. Enable Line Numbering in Eclipse Open Eclipse, then go to: Window -> Preferences -> General -> Editors -> Text Editors -> Check.
String Class. Objectives and Goals Identify 2 types of Strings: Literal & Symbolic. Learn about String constructors and commonly used methods Learn several.
From C++ to Java A whirlwind tour of Java for C++ programmers.
Chapter 7 Strings  Use the String class to process fixed strings.  Use the StringBuffer class to process flexible strings.  Use the StringTokenizer.
String Manipulation. Java String class  The String class represents character strings “Tammy Bailey”  All strings (arrays of characters) in Java programs.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
Java Overview. Comments in a Java Program Comments can be single line comments like C++ Example: //This is a Java Comment Comments can be spread over.
Characters and Strings. Characters  New primitive char  char letter; letter = ‘a’; char letter2 = ‘C’;  Because computers can only represent numbers,
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.
G51PR1 Introduction to Programming I University of Nottingham Unit 8 : Strings.
Strings And other things. Strings Overview The String Class and its methods The char data type and Character class StringBuilder, StringTokenizer classes.
CSI 3125, Preliminaries, page 1 String. CSI 3125, Preliminaries, page 2 String Class Java provides the String class to create and manipulate strings.
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.
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:
Strings Methods in the String class Manipulating text in Java.
17-Feb-16 String and StringBuilder Part I: String.
Declaring variables The type could be: int double char String name is anything you want like lowerCaseWord.
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.
(Dreaded) Quiz 2 Next Monday.
Chapter 8 String Manipulation
Introduction to programming in java
String and StringBuffer classes
Java String Methods - Codehs
C# - Strings.
Lecture 8: The String class
String class.
EKT 472: Object Oriented Programming
Programming in Java Text Books :
String Handling in JAVA
String class in java Visit for more Learning Resources string.
Modern Programming Tools And Techniques-I Lecture 11: String Handling
String and StringBuilder
F4105 JAVA PROGRAMMING F4105 Java Programming
Chapter 7: Strings and Characters
Object Oriented Programming
תרגול מס' 3 עבודה עם מחרוזות (Strings) מתודות (Methods) העברת פרמטרים
String and StringBuilder
Tonga Institute of Higher Education
String and StringBuilder
Java – String Handling.
Lecture 10 Strings CSE /26/2018.
String and StringBuilder
String methods 26-Apr-19.
Strings in Java.
Chapter 2: Java Fundamentals cont’d
Exam Prep.
In Java, strings are objects that belong to class java.lang.String .
Strings in Java Strings in Java are also a reference type.
Methods in the String class Manipulating text in Java
What We Want To Do User enters: Mary Smith
Presentation transcript:

String Methods

String message = " HELLO you! "; Strings String myString = "abcDEFMNopqrstYZ"; String message = " HELLO you! "; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 'a' 'b' 'c' 'D' 'E' 'F' 'M' 'N' 'o' 'p' 'q' 'r' 's' 't' 'Y' 'Z' 1 2 3 4 5 6 7 8 9 10 11 12 13 ' ' 'H' 'E' 'L' 'O' 'y' 'o' 'u' '!'

String Methods length() charAt(int index) toLowerCase() toUpperCase() equals(String s) equalsIgnoreCase(String s) returns the length (number of characters) of a string returns character at index position converts the supplied String to lowercase converts the supplied String to uppercase compares 2 Strings – returns a boolean value (true/false) compares 2 Strings (ignoring case) – returns a boolean value (true/false)

String Methods replace(char x, char y) trim() substring(int begin) substring(int begin, int end) concat(String s) returns a new String with all occurrences of the character x replaced with the character y returns a new String with all leading and trailing spaces removed returns a new String starting at begin index to the end of the String returns a new String starting at begin index to (end – 1) index (NB) returns a new String with s appended to the end of the String

String Methods Printing out each character in a string individually: String name = “Martin"; for (int index = 0; index < name.length(); index++) System.out.print(name.charAt(index) + "\t"); System.out.println(); USEFUL: Checking if a character is uppercase (similar for lower case): if (Character.isUpperCase(name.charAt(0))) { System.out.println("'" + name.charAt(0) + "' is uppercase"); }//if else { System.out.println("'" + name.charAt(0) + "' is not uppercase"); }//else

String message = " HELLO you! "; Strings String myString = "abcDEFMNopqrstYZ"; String message = " HELLO you! "; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 'a' 'b' 'c' 'D' 'E' 'F' 'M' 'N' 'o' 'p' 'q' 'r' 's' 't' 'Y' 'Z' 1 2 3 4 5 6 7 8 9 10 11 12 13 ' ' 'H' 'E' 'L' 'O' 'y' 'o' 'u' '!'

String myString = ”abcDEFMNopqrstYZ"; String message = " HELLO you! "; myString.length() myString.charAt(5) message.equals(" hello you! ") myString.toLowerCase() myString.toUpperCase() message.equalsIgnoreCase(" hello you! ") message.replace('L', '*') message.trim() message.substring(8) myString.substring(5,10) message.concat("!!!") myString.endsWith("stYZ") message.startsWith("HELLO") 16 'F' false "abcdefmnopqrstyz" "ABCDEFMNOPQRSTYZ" true " HE**O you! " "HELLO you!" "you! " "FMNop" " HELLO you! !!!"

String myString = "abcDEFMNopqrstYZ"; String message = " HELLO you! "; message.length() message.charAt(5) myString.equals(“abcDEFMNopqrstYZ") message.toLowerCase() message.toUpperCase() myString.equalsIgnoreCase(“ABCDEFMNOPQRSTYZ") myString.replace(‘Z', '*') myString.trim() myString.substring(8) message.substring(5,10) myString.concat("!!!") message.endsWith(“you!") myString.startsWith(“ HELLO") 14 ‘L' true " hello you! ” " HELLO YOU! " " abcDEFMNopqrstY*" "abcDEFMNopqrstYZ" "opqrstYZ" "LO yo" "abcDEFMNopqrstYZ!!!" false