Unit-2 Objects and Classes

Slides:



Advertisements
Similar presentations
1 Arrays, Strings and Collections [2] Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software Engineering.
Advertisements

Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
The ArrayList Class and the enum Keyword
1 StringBuffer & StringTokenizer Classes Chapter 5 - Other String Classes.
Purpose : To convert this string to a new character array. Return Type : char[ ] Parameters : none Declaration : public char[ ] toCharArray() Returns.
Java POWERED BY: ARVIND DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING RADHA GOVIND GROUP OF INSTITUTIONS,MEERUT.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 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 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.
Java Programming Strings Chapter 7.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 9 Strings and Text I/O.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 8 Strings and Text.
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
1 String Buffer & String Tokenizer Overview l Overview of String Buffer class and Methods l Overview of String Tokenizer class and methods l Preview: Notions.
CSM-Java Programming-I Spring,2005 String Handling Lesson - 6.
StringBuffer class  Alternative to String class  Can be used wherever a string is used  More flexible than String  Has three constructors and more.
Fundamental Programming Structures in Java: Strings.
28-Jun-15 String and StringBuilder Part I: String.
Strings, StringBuilder, StringBuffer. String Strings in java are immutable Once created they cannot be altered and hence any alterations will lead to.
Characters, Strings and the String Buffer Jim Burns.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 7 Strings.
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
Chapter 7 Strings  Use the String class to process fixed strings.  Use the StringBuffer class to process flexible strings.  Use the StringTokenizer.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 8 Strings 1.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
Chapter 7: Characters, Strings, and the StringBuilder.
String Handling StringBuffer class character class StringTokenizer class.
Jaeki Song JAVA Lecture 07 String. Jaeki Song JAVA Outline String class String comparisons String conversions StringBuffer class StringTokenizer class.
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 String Builder. System.String string is the alias for System.String A string is an object of class string in the System namespace representing.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 8 Strings.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
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,
17-Feb-16 String and StringBuilder Part I: String.
1 Unit-2 Arrays, Strings and Collections. 2 Arrays - Introduction An array is a group of contiguous or related data items that share a common name. Used.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 10 Thinking in Objects.
String & Exception. Lesson plan Class & Object String Exercise for midterm.
Chapter 9 Strings and Text I/O
String and StringBuffer classes
JAVA API Strings, I/O, Formatting and Parsing
Strings, StringBuilder, and Character
Strings.
The StringBuffer Class 
EKT 472: Object Oriented Programming
String and String Buffers
String String Builder.
String and StringBuilder
F4105 JAVA PROGRAMMING F4105 Java Programming
Chapter 7: Strings and Characters
String and StringBuilder
Lecture Set 6 The String and DateTime Data Types
Java – String Handling.
Chapter 9 Strings.
class PrintOnetoTen { public static void main(String args[]) {
Lecture 07 String Jaeki Song.
String and StringBuilder
Chapter 9 Strings and Text I/O
Dr. Sampath Jayarathna Cal Poly Pomona
Chapter 10 Thinking in Objects Part 2
Object Oriented Programming
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
Objects with ArrayLists as Attributes
In Java, strings are objects that belong to class java.lang.String .
Presentation transcript:

Unit-2 Objects and Classes String Buffer(String Builder) Class

The String Builder/String Buffer class is an alternative to the String class. In general, a String Builder/String Buffer can be used wherever a string is used. String Builder/String Buffer is more flexible than String. You can add, insert, or append new contents into a String Builder or a String Buffer, whereas the value of a String object is fixed, once the string is created. The constructors and methods in StringBuffer and StringBuilder are almost the same.

String Builder class

Modifying Strings in the StringBuilder You can append new contents at the end of a string builder, insert new contents at a specified position in a string builder, and delete or replace characters in a string builder, using the methods listed below.

Append Method

Insert Method

Delete,reverse,replace,CharAt Method

The toString, capacity, length, setLength, and charAt Methods

Program //program of capacity and length function of string buffer. Class StringBufferDemo { Public static void main(String args[]) StringBuffer str=new StringBuffer(“java”); System.out.println(“length is:”+str.length()); System.out.println(“Capacity is:”+str.capacity()); } OutPut: Length is:4 Capacity is:20 Note: capacity function returns the number of characters in the string + 16 additional characters.

Program //program to convert the string “Great” to new string “God”. Class StringBufferDemo { Public static void main(String args[]) StringBuffer str=new StringBuffer(“Great”); str.setCharAt(1,’o’); str.setCharAt(2,’d’); Str.setLength(3); System.out.println(“New string is”+str); } OutPut: New string is:God