Java Strings in 10 minutes

Slides:



Advertisements
Similar presentations
JavaScript Chapter 7 Working with Strings. String Operations (Chap 2) var colors = red blue; var colors = red blue; var sizes = small large; var sizes.
Advertisements

Java
Classes and objects Learning objectives By the end of this lecture you should be able to: explain the meaning of the term object-oriented; explain the.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
String Processing Word processing term papers, writing memoirs, sending messages, responding to surveys, placing online orders and registering.
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Strings in Java 1. strings in java are handled by two classes String &
Strings Testing for equality with strings.
MSc IT Programming Methodology (2). number name number.
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.
Programming 2 CS112- Lab 2 Java
CIS 234: Strings. What Is a String? series of characters enclosed in double quotes characters can include letters (lower case and upper case), digits,
CSM-Java Programming-I Spring,2005 String Handling Lesson - 6.
Strings In Java, strings are contained in an object that is an instance of the String class. String in java is the name of a class. That’s why it starts.
Strings Reading for this Lecture, L&L, 3.2. Strings String is basically just a collection of characters. Thus, the string “Martyn” could be thought of.
Lab session 3 and 4 Topics to be covered Escape sequences Escape sequences Variables /identifiers Variables /identifiers Constants Constants assignment.
Sanjay Goel, School of Business, University at Albany, SUNY 1 MSI 692: Special Topics in Information Technology Lecture 4: Strings & Arrays Sanjay Goel.
JAVA LIBRARY CLASSES CITS Main concepts to be covered Using library classes: String, Math, Color Reading documentation Java 7 API is available.
© 2007 Lawrenceville Press Slide 1 Chapter 6 The while Statement  Loop structure that executes a set of statements as long as a condition is true  The.
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.
String Manipulation Chapter 15 This chapter explains the String facilities. You have already seen some of the main methods of the String class.
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.
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.
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.
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.
Strings in Java. What data types have we seen so far?
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.
Chapter 8 String Manipulation
The Methods and What You Need to Know for the AP Exam
Strings A String is a sequence of letters
Java String Methods - Codehs
strings, if/else, user input
Introduction to Calculated Columns Variables, Conditionals, and String Manipulation PRESENTER: Cameron Blashka| Informer Implementation Specialist| April.
Assist. Prof. Rassim Suliyev - SDU 2017
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
String class.
EKT 472: Object Oriented Programming
Chapter 6 The while Statement
String Objects & its Methods
Chapter 7: Strings and Characters
Object Oriented Programming
MSIS 655 Advanced Business Applications Programming
Part a: Fundamentals & Class String
Tonga Institute of Higher Education
The compareTo interface
16 Strings.
Microsoft Visual Basic 2005: Reloaded Second Edition
CS2011 Introduction to Programming I Strings
String Processing 1 MIS 3406 Department of MIS Fox School of Business
Strings in Java.
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
Pre-AP® Computer Science Quiz
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.
What We Want To Do User enters: Mary Smith
Presentation transcript:

Java Strings in 10 minutes

Declaring/creating a new String String strName = ""; String str = "WLCS"; String str2 = "Hello"; //String is the type name

Size/length of a string String str = "WLCS"; System.out.println( str.length() ); //returns 4

String Library of Methods Strings have many pre-made methods in Java Examples length() equals() substring() Etc. Java String Library

Comparing if Strings are equal == does NOT work Must use the .equals() method str2.equals("Hello"); //returns true strName.equals(str2); //return false

Substrings (Strings slices) strName.substring(a,b) Returns a substring from index a up to b (exclusive) String str = "Hello, world"; System.out.println( str.substring(0,5) ); //returns Hello System.out.println( str.substring(7, str.length()) ); //returns World

Searching for a substring strName.indexOf(String substr) returns the index of the specific substr String str = "Hello, world"; System.out.println( str.indexOf(",") ); //returns 5 System.out.println( str.indexOf("wo") ); //returns 7 System.out.println( str.indexOf("qwerty") ); //returns -1

Comparing Strings alphabetically strName.compareTo(String str) returns an integer indicating alphabetical order String str1 = "abc"; String str2 = "def"; System.out.println(str1.compareTo(str2)); //returns -3 System.out.println(str1.compareTo(str1)); //returns 0 System.out.println(str2.compareTo(str1)); //returns 3

compareTo() example String str1 = "abc"; String str2 = "def"; if (str1.compareTo(str2) < 0) { System.out.println(str1 + " goes before " + str2); }

Other useful String methods toLowerCase() toUpperCase() trim() split()