SlideShare a Scribd company logo
CONTENT
Types of array
String and StringBuffer
Class
Method of StringBuffer
Class
Array
• Array is similar type of elements and share a common name.
• Syntax
datatype variblename [ ] = new type [size of array]
• Example
int a [ ] = new int [7]
•Types of array :
1) Single dimension array
2) Multi dimension array
Single dimension array
• Syntax
int a[ ] = new int [ 10 ]
• An array using one subscript to represent the list of element is called
Single dimension array.
Multi dimension array
• Syntax
int a [ ] = new int [3] [3]
row column
• In Java , multi dimension array is actually array of arrays.
Stringclass
• An obj of the string class represent a string of class.
• String class belong the java.lang package which does not require the input-output
statement.
• Like , other classes string has constructor and methods.
• Syntax :
String s = new String (“hello”);
System.out.println(s);
String s1 = new String (s);
String s = “hello world”;
System.out.println(s);
StringBufferclass
• The java.lang.StringBuffer class is a mutable sequence of characters.
• A String buffer is like a string , but can be modified.
• It contains some sequence of characters , but the length and content
of the sequence can be changed through certain method calls.
• They are safe for by multiple threads.
• Syntax
StringBuffer sb = new StringBuffer ();
DifferencebetweenStringandStringBuffer
BASIS FOR COMPARISON STRING STRINGBUFFER
Basic The length of the String object is
fixed.
The length of the StringBuffer can
be increased.
Modification String object is immutable. StringBuffer object is mutable.
Performance It is slower during concatenation. It is faster during concatenation.
Memory Consumes more memory. Consumes less memory.
Method of StringBuffer class
METHODS
Description
SetLength ( int size) It is used to set the length of string.
CharAt (int index) It returns the character at the specified index in a string.
SetcharAt (int index , char ch) It is used to set the specified character at the given
index. It replacing the old character at the given index.
append (String s) It is used to append the specified string with this String.
Insert (int index , String str) It is used to insert the specified String at the specified
position.
reverse( ) It is used to reverse the string.
replace (int startindex , int endindex ,String str) It is used to replace the string from specified startindex
and endindex.
getchars (int S , int E , char a[ ] , int
target)
Where , S = startindex
E = endindex
It is used for copying String characters to an array of
chars.
Ex :
StringBuffer sb = new StringBuffer (“Java Program”);
Char[ ] dst = new char[ ] {‘s’ , ‘t’ , ‘r’ , ‘i’ , ‘n’ , ‘g’ , ‘B’ ,
‘u’ , ‘f’ , ‘f’ , ‘e’ , ‘r’ };
Sb.getchars(5,12,dst,2);
System.out.println(dst); //stProgramer
ExampleofmethodStringBufferclass
• StringBuffer sb = new StringBuffer (“VIE”);
sb.SetLength (2); //VI
• char c = sb.charAt (1);
System.out.println(c); // V
• sb.SetcharAt ( 0 , ‘A’);
System.out.println(sb.toString()); //AIE
• String str = “college”;
sb.append(str);
System.out.println(sb.toString()); //VIE college
• sb.insert (1 , “kotambi”);
System.out.println(sb.toString()); //VkotambiIE
• sb.reverse ();
System.out.println(sb.toString()); //EIV
• StringBuffer sb = new StringBuffer (“hellobye”);
sb.replace(5,7,”hi”);
System.out.println(sb.toString()); // hellohibye
Java

More Related Content

PPTX
arrays of structures
PDF
Python strings
PDF
Java -lec-6
PDF
Anton Kasyanov, Introduction to Python, Lecture4
PPTX
Java arrays
arrays of structures
Python strings
Java -lec-6
Anton Kasyanov, Introduction to Python, Lecture4
Java arrays

What's hot (20)

DOC
Arrays and Strings
PDF
String handling(string buffer class)
PDF
Java arrays
PDF
Python :variable types
PPTX
ARRAY
PDF
Java Arrays
PPTX
OOPs with java
PPTX
L14 string handling(string buffer class)
PPTX
Array in C# 3.5
PPTX
Data Structures in Python
PPTX
C# Arrays
PDF
An Introduction to Programming in Java: Arrays
PPTX
6 arrays injava
PPT
String Handling
PPT
C++ Arrays
PDF
Java chapter 6 - Arrays -syntax and use
PPTX
String in python lecture (3)
PPT
Array
PPT
Arrays Basics
Arrays and Strings
String handling(string buffer class)
Java arrays
Python :variable types
ARRAY
Java Arrays
OOPs with java
L14 string handling(string buffer class)
Array in C# 3.5
Data Structures in Python
C# Arrays
An Introduction to Programming in Java: Arrays
6 arrays injava
String Handling
C++ Arrays
Java chapter 6 - Arrays -syntax and use
String in python lecture (3)
Array
Arrays Basics
Ad

Similar to Java (20)

PPT
Strings Arrays
PPTX
In the given example only one object will be created. Firstly JVM will not fi...
PPT
Java Strings methods and operations.ppt
PPTX
Strings in Java
PPTX
javastringexample problems using string class
PPTX
Fileoperations.pptx
PPTX
STRING CLASS AND STRING BUFFER CLASS CONCEPTS IN JAVA
PPTX
Java string handling
PPT
Chapter 9 - Characters and Strings
PPT
Java căn bản - Chapter9
PPT
07slide
PDF
Lecture3pptx_____2024_08_28_22_04_02.pdf
PPTX
String handling
PPTX
package
PPTX
StringBuffer.pptx
PDF
DOC-20250225-WA0016..pptx_20250225_232439_0000.pdf
PPT
Strings In OOP(Object oriented programming)
PPT
ch06.ppt
PPT
PPT
array Details
Strings Arrays
In the given example only one object will be created. Firstly JVM will not fi...
Java Strings methods and operations.ppt
Strings in Java
javastringexample problems using string class
Fileoperations.pptx
STRING CLASS AND STRING BUFFER CLASS CONCEPTS IN JAVA
Java string handling
Chapter 9 - Characters and Strings
Java căn bản - Chapter9
07slide
Lecture3pptx_____2024_08_28_22_04_02.pdf
String handling
package
StringBuffer.pptx
DOC-20250225-WA0016..pptx_20250225_232439_0000.pdf
Strings In OOP(Object oriented programming)
ch06.ppt
array Details
Ad

More from JahnaviBhagat (10)

PPTX
PPTX
PPTX
System Programming
PPTX
Indeterminate forms
PPTX
Contributor personality development
PPTX
Electrical engineering
PPTX
computer organization
PPTX
Computer Network
PPTX
System Programming
Indeterminate forms
Contributor personality development
Electrical engineering
computer organization
Computer Network

Recently uploaded (20)

PDF
Queuing formulas to evaluate throughputs and servers
PPTX
Glazing at Facade, functions, types of glazing
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
flutter Launcher Icons, Splash Screens & Fonts
PPTX
TE-AI-Unit VI notes using planning model
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPT
Chapter 6 Design in software Engineeing.ppt
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
PPTX
Practice Questions on recent development part 1.pptx
PDF
July 2025: Top 10 Read Articles Advanced Information Technology
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PPTX
“Next-Gen AI: Trends Reshaping Our World”
PPTX
AgentX UiPath Community Webinar series - Delhi
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
Queuing formulas to evaluate throughputs and servers
Glazing at Facade, functions, types of glazing
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Arduino robotics embedded978-1-4302-3184-4.pdf
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
flutter Launcher Icons, Splash Screens & Fonts
TE-AI-Unit VI notes using planning model
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
bas. eng. economics group 4 presentation 1.pptx
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Chapter 6 Design in software Engineeing.ppt
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
Practice Questions on recent development part 1.pptx
July 2025: Top 10 Read Articles Advanced Information Technology
OOP with Java - Java Introduction (Basics)
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
“Next-Gen AI: Trends Reshaping Our World”
AgentX UiPath Community Webinar series - Delhi
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation

Java

  • 1. CONTENT Types of array String and StringBuffer Class Method of StringBuffer Class
  • 2. Array • Array is similar type of elements and share a common name. • Syntax datatype variblename [ ] = new type [size of array] • Example int a [ ] = new int [7] •Types of array : 1) Single dimension array 2) Multi dimension array
  • 3. Single dimension array • Syntax int a[ ] = new int [ 10 ] • An array using one subscript to represent the list of element is called Single dimension array. Multi dimension array • Syntax int a [ ] = new int [3] [3] row column • In Java , multi dimension array is actually array of arrays.
  • 4. Stringclass • An obj of the string class represent a string of class. • String class belong the java.lang package which does not require the input-output statement. • Like , other classes string has constructor and methods. • Syntax : String s = new String (“hello”); System.out.println(s); String s1 = new String (s); String s = “hello world”; System.out.println(s);
  • 5. StringBufferclass • The java.lang.StringBuffer class is a mutable sequence of characters. • A String buffer is like a string , but can be modified. • It contains some sequence of characters , but the length and content of the sequence can be changed through certain method calls. • They are safe for by multiple threads. • Syntax StringBuffer sb = new StringBuffer ();
  • 6. DifferencebetweenStringandStringBuffer BASIS FOR COMPARISON STRING STRINGBUFFER Basic The length of the String object is fixed. The length of the StringBuffer can be increased. Modification String object is immutable. StringBuffer object is mutable. Performance It is slower during concatenation. It is faster during concatenation. Memory Consumes more memory. Consumes less memory.
  • 7. Method of StringBuffer class METHODS Description SetLength ( int size) It is used to set the length of string. CharAt (int index) It returns the character at the specified index in a string. SetcharAt (int index , char ch) It is used to set the specified character at the given index. It replacing the old character at the given index. append (String s) It is used to append the specified string with this String. Insert (int index , String str) It is used to insert the specified String at the specified position. reverse( ) It is used to reverse the string. replace (int startindex , int endindex ,String str) It is used to replace the string from specified startindex and endindex.
  • 8. getchars (int S , int E , char a[ ] , int target) Where , S = startindex E = endindex It is used for copying String characters to an array of chars. Ex : StringBuffer sb = new StringBuffer (“Java Program”); Char[ ] dst = new char[ ] {‘s’ , ‘t’ , ‘r’ , ‘i’ , ‘n’ , ‘g’ , ‘B’ , ‘u’ , ‘f’ , ‘f’ , ‘e’ , ‘r’ }; Sb.getchars(5,12,dst,2); System.out.println(dst); //stProgramer
  • 9. ExampleofmethodStringBufferclass • StringBuffer sb = new StringBuffer (“VIE”); sb.SetLength (2); //VI • char c = sb.charAt (1); System.out.println(c); // V • sb.SetcharAt ( 0 , ‘A’); System.out.println(sb.toString()); //AIE • String str = “college”; sb.append(str); System.out.println(sb.toString()); //VIE college • sb.insert (1 , “kotambi”); System.out.println(sb.toString()); //VkotambiIE
  • 10. • sb.reverse (); System.out.println(sb.toString()); //EIV • StringBuffer sb = new StringBuffer (“hellobye”); sb.replace(5,7,”hi”); System.out.println(sb.toString()); // hellohibye