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

What's hot

Chap 7(array)
Chap 7(array)Chap 7(array)
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
Dr.Subha Krishna
 
String handling(string buffer class)
String handling(string buffer class)String handling(string buffer class)
String handling(string buffer class)
Ravi Kant Sahu
 
Java arrays
Java arraysJava arrays
Java arrays
Kuppusamy P
 
Python :variable types
Python :variable typesPython :variable types
Python :variable types
S.M. Salaquzzaman
 
ARRAY
ARRAYARRAY
ARRAY
ayush raj
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
OXUS 20
 
OOPs with java
OOPs with javaOOPs with java
OOPs with java
AAKANKSHA JAIN
 
L14 string handling(string buffer class)
L14 string handling(string buffer class)L14 string handling(string buffer class)
L14 string handling(string buffer class)
teach4uin
 
Array in C# 3.5
Array in C# 3.5Array in C# 3.5
Array in C# 3.5
Gopal Ji Singh
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
Devashish Kumar
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
Hock Leng PUAH
 
An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: Arrays
Martin Chapman
 
6 arrays injava
6 arrays injava6 arrays injava
6 arrays injava
irdginfo
 
String Handling
String HandlingString Handling
String Handling
Bharat17485
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
أحمد محمد
 
Java chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and useJava chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and use
Mukesh Tekwani
 
String in python lecture (3)
String in python lecture (3)String in python lecture (3)
String in python lecture (3)
Ali ٍSattar
 
Array
ArrayArray
Array
Hajar
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
Nikhil Pandit
 

What's hot (20)

Chap 7(array)
Chap 7(array)Chap 7(array)
Chap 7(array)
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
String handling(string buffer class)
String handling(string buffer class)String handling(string buffer class)
String handling(string buffer class)
 
Java arrays
Java arraysJava arrays
Java arrays
 
Python :variable types
Python :variable typesPython :variable types
Python :variable types
 
ARRAY
ARRAYARRAY
ARRAY
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
OOPs with java
OOPs with javaOOPs with java
OOPs with java
 
L14 string handling(string buffer class)
L14 string handling(string buffer class)L14 string handling(string buffer class)
L14 string handling(string buffer class)
 
Array in C# 3.5
Array in C# 3.5Array in C# 3.5
Array in C# 3.5
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
 
An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: Arrays
 
6 arrays injava
6 arrays injava6 arrays injava
6 arrays injava
 
String Handling
String HandlingString Handling
String Handling
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Java chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and useJava chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and use
 
String in python lecture (3)
String in python lecture (3)String in python lecture (3)
String in python lecture (3)
 
Array
ArrayArray
Array
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
 

Similar to Java

Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
phanleson
 
In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...
Indu32
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
Abhilash Nair
 
javastringexample problems using string class
javastringexample problems using string classjavastringexample problems using string class
javastringexample problems using string class
fedcoordinator
 
Fileoperations.pptx
Fileoperations.pptxFileoperations.pptx
Fileoperations.pptx
VeenaNaik23
 
Java string handling
Java string handlingJava string handling
Java string handling
Salman Khan
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
Eduardo Bergavera
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
Vince Vo
 
07slide
07slide07slide
07slide
Aboudi Sabbah
 
String handling
String handlingString handling
String handling
ssuser20c32b
 
package
packagepackage
package
sweetysweety8
 
StringBuffer.pptx
StringBuffer.pptxStringBuffer.pptx
StringBuffer.pptx
meenakshi pareek
 
Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)
Danial Virk
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
valerie5142000
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
ansariparveen06
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
AqeelAbbas94
 
array Details
array Detailsarray Details
array Details
shivas379526
 
String Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesString Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and Interfaces
Prabu U
 
Arrays
ArraysArrays

Similar to Java (20)

Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
 
In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
javastringexample problems using string class
javastringexample problems using string classjavastringexample problems using string class
javastringexample problems using string class
 
Fileoperations.pptx
Fileoperations.pptxFileoperations.pptx
Fileoperations.pptx
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
 
07slide
07slide07slide
07slide
 
String handling
String handlingString handling
String handling
 
package
packagepackage
package
 
StringBuffer.pptx
StringBuffer.pptxStringBuffer.pptx
StringBuffer.pptx
 
Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
array Details
array Detailsarray Details
array Details
 
String Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesString Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and Interfaces
 
Arrays
ArraysArrays
Arrays
 

More from JahnaviBhagat

Se
SeSe
A.java
A.javaA.java
Mpi
MpiMpi
System Programming
System ProgrammingSystem Programming
System Programming
JahnaviBhagat
 
Indeterminate forms
Indeterminate formsIndeterminate forms
Indeterminate forms
JahnaviBhagat
 
Contributor personality development
Contributor personality development Contributor personality development
Contributor personality development
JahnaviBhagat
 
Electrical engineering
Electrical engineeringElectrical engineering
Electrical engineering
JahnaviBhagat
 
computer organization
computer organizationcomputer organization
computer organization
JahnaviBhagat
 
Computer Network
Computer NetworkComputer Network
Computer Network
JahnaviBhagat
 
Dbms
DbmsDbms

More from JahnaviBhagat (10)

Se
SeSe
Se
 
A.java
A.javaA.java
A.java
 
Mpi
MpiMpi
Mpi
 
System Programming
System ProgrammingSystem Programming
System Programming
 
Indeterminate forms
Indeterminate formsIndeterminate forms
Indeterminate forms
 
Contributor personality development
Contributor personality development Contributor personality development
Contributor personality development
 
Electrical engineering
Electrical engineeringElectrical engineering
Electrical engineering
 
computer organization
computer organizationcomputer organization
computer organization
 
Computer Network
Computer NetworkComputer Network
Computer Network
 
Dbms
DbmsDbms
Dbms
 

Recently uploaded

Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
Aditya Rajan Patra
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
NazakatAliKhoso2
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 

Recently uploaded (20)

Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 

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