SlideShare a Scribd company logo
1 of 18
Program: B.Tech, CSE, 3rdsem, 2nd year
CS 306: Java Lab
Unit-1
Ravi Parashar
Assistant Professor, Computer Science & Engineering
July-Dec, 2021 / Lecture No. 13
Part II-String handling in Java
Outlines
• Prerequisite
• Objective
• String constructors
• Methods of String class
• Learning Outcome
• References
Prerequisite
• Basics understanding of C/C++ language.
• Logic building skills.
• Experience writing code in a any programming language.
Objective
• To acquire Basic understanding in Java
• To develop the skill of working in Java
•To able to understand string of Java
String Constructors
1.String()- it is default constructor ,used to create empty string.
Syntax:-
String x=new String();
Here x is an object.
2.String(string):- it is parameterized constructor.
Syntax:- String x= new String(“Gwalior”);
3.String(char[],int p,int n):- In this p is position from where
characters are read,n is the number of characters to be read.
5
CS 306 Reference No.: R1
SELO: 1,2
Program for parameterized constructor
class check
{
public static void main(String ar[])
{
char x={‘G’,’W’,’A’,’L’,’I’,’O’,’R’};
String x=new String(x,2,3);
System.out.println (x);
}
} 6
CS 306 Reference No.: R1
SELO: 1,2
Output
ALI
note : - if we write the string as
String s=“GWALIOR”;
Here s,indicates the base address of string.
7
CS 306 Reference No.: R1
SELO: 1,2
Various methods of String class
1. int length()- this method returns the number of characters on
string.
Ex. Class check
{
public static void main (String ar[])
{
String x= new String(“Gwalior”);
System.out. println(x.length());
}}
8
CS 306 Reference No.: R1
SELO: 1,2
Output:-
7
9
CS 306 Reference No.: R1
SELO: 1,2
2. toUpperCase():- It converts all rhe characters in a string
from lowercase to uppercase.
3.toLowerCase():- It converts all characters from uppercase to
lowercase.
Ex. class check
{
public static void main (String ar[])
{
String z= new String (“ gwalior”);
10
CS 306 Reference No.: R1
SELO: 1,2
String p=z.toUpperCase();
System.out.println (p);
System.out.println (z);
} }
Output:-
GWALIOR
gwalior
11
CS 306 Reference No.: R1
SELO: 1,2
4. boolean equals(String)- If we want to compare string
values.If both strings are equal then this method returns true
otherwise returns false.
Ex. class check
{
public static void main(String ar[])
{
String x=new String(“Gwalior”);
String y=new String (“Gwalior”);
12
CS 306 Reference No.: R1
SELO: 1,2
if(x.equals(y))
{
System.out.println (“equal”);
}
else
System.out.println (“not equal”);
}
Output: equal
13
CS 306 Reference No.: R1
SELO: 1,2
5. boolean equalsIgnoreCase(String):this method ignores the
cases and compares the strings.
6.int compareTo(String):- It is used to compare two strings.
-If string1 is greater than String2 this method returns + ve
value
-If string1 is lesser than string2 then this method returns –ve
value.
-If string1==string2 this function returns zero.
14
CS 306 Reference No.: R1
SELO: 1,2
Ex. if((x.compareTo(y))>0)
{
System.out.println (“string1 is greater”);
}
else if(x.compareTo(y))<0)
System.out.println (“String2 is greater”);
else
System.out.println (“both strings are equals”);
}
15
CS 306 Reference No.: R1
SELO: 1,2
Learning Outcomes
• Understand the basic concept in Java
• To understand used of Java
• Be able to work in Java
References
1. Herbert schildt ,”The complete Reference Java” ,TMH
publications.
L-13 part2-string handling.pptx

More Related Content

Similar to L-13 part2-string handling.pptx

The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type PatternsSimon Ritter
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text ProcessingIntro C# Book
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in PythonSujith Kumar
 
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策kwatch
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Sagar Verma
 
16 strings-and-text-processing-120712074956-phpapp02
16 strings-and-text-processing-120712074956-phpapp0216 strings-and-text-processing-120712074956-phpapp02
16 strings-and-text-processing-120712074956-phpapp02Abdul Samee
 
Module 3 - Regular Expressions, Dictionaries.pdf
Module 3 - Regular  Expressions,  Dictionaries.pdfModule 3 - Regular  Expressions,  Dictionaries.pdf
Module 3 - Regular Expressions, Dictionaries.pdfGaneshRaghu4
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaSandesh Sharma
 
Top 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdetTop 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdetDevLabs Alliance
 
C++ Strings.ppt
C++ Strings.pptC++ Strings.ppt
C++ Strings.pptDilanAlmsa
 
Strings in c
Strings in cStrings in c
Strings in cvampugani
 
String and string buffer
String and string bufferString and string buffer
String and string bufferkamal kotecha
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)Tak Lee
 

Similar to L-13 part2-string handling.pptx (20)

The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type Patterns
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text Processing
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
 
16 strings-and-text-processing-120712074956-phpapp02
16 strings-and-text-processing-120712074956-phpapp0216 strings-and-text-processing-120712074956-phpapp02
16 strings-and-text-processing-120712074956-phpapp02
 
Strings in java
Strings in javaStrings in java
Strings in java
 
String slide
String slideString slide
String slide
 
Module 3 - Regular Expressions, Dictionaries.pdf
Module 3 - Regular  Expressions,  Dictionaries.pdfModule 3 - Regular  Expressions,  Dictionaries.pdf
Module 3 - Regular Expressions, Dictionaries.pdf
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
java-programming.pdf
java-programming.pdfjava-programming.pdf
java-programming.pdf
 
Strings part2
Strings part2Strings part2
Strings part2
 
Top 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdetTop 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdet
 
C++ Strings.ppt
C++ Strings.pptC++ Strings.ppt
C++ Strings.ppt
 
Strings in c
Strings in cStrings in c
Strings in c
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)
 

Recently uploaded

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 

Recently uploaded (20)

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 

L-13 part2-string handling.pptx

  • 1. Program: B.Tech, CSE, 3rdsem, 2nd year CS 306: Java Lab Unit-1 Ravi Parashar Assistant Professor, Computer Science & Engineering July-Dec, 2021 / Lecture No. 13 Part II-String handling in Java
  • 2. Outlines • Prerequisite • Objective • String constructors • Methods of String class • Learning Outcome • References
  • 3. Prerequisite • Basics understanding of C/C++ language. • Logic building skills. • Experience writing code in a any programming language.
  • 4. Objective • To acquire Basic understanding in Java • To develop the skill of working in Java •To able to understand string of Java
  • 5. String Constructors 1.String()- it is default constructor ,used to create empty string. Syntax:- String x=new String(); Here x is an object. 2.String(string):- it is parameterized constructor. Syntax:- String x= new String(“Gwalior”); 3.String(char[],int p,int n):- In this p is position from where characters are read,n is the number of characters to be read. 5 CS 306 Reference No.: R1 SELO: 1,2
  • 6. Program for parameterized constructor class check { public static void main(String ar[]) { char x={‘G’,’W’,’A’,’L’,’I’,’O’,’R’}; String x=new String(x,2,3); System.out.println (x); } } 6 CS 306 Reference No.: R1 SELO: 1,2
  • 7. Output ALI note : - if we write the string as String s=“GWALIOR”; Here s,indicates the base address of string. 7 CS 306 Reference No.: R1 SELO: 1,2
  • 8. Various methods of String class 1. int length()- this method returns the number of characters on string. Ex. Class check { public static void main (String ar[]) { String x= new String(“Gwalior”); System.out. println(x.length()); }} 8 CS 306 Reference No.: R1 SELO: 1,2
  • 9. Output:- 7 9 CS 306 Reference No.: R1 SELO: 1,2
  • 10. 2. toUpperCase():- It converts all rhe characters in a string from lowercase to uppercase. 3.toLowerCase():- It converts all characters from uppercase to lowercase. Ex. class check { public static void main (String ar[]) { String z= new String (“ gwalior”); 10 CS 306 Reference No.: R1 SELO: 1,2
  • 11. String p=z.toUpperCase(); System.out.println (p); System.out.println (z); } } Output:- GWALIOR gwalior 11 CS 306 Reference No.: R1 SELO: 1,2
  • 12. 4. boolean equals(String)- If we want to compare string values.If both strings are equal then this method returns true otherwise returns false. Ex. class check { public static void main(String ar[]) { String x=new String(“Gwalior”); String y=new String (“Gwalior”); 12 CS 306 Reference No.: R1 SELO: 1,2
  • 13. if(x.equals(y)) { System.out.println (“equal”); } else System.out.println (“not equal”); } Output: equal 13 CS 306 Reference No.: R1 SELO: 1,2
  • 14. 5. boolean equalsIgnoreCase(String):this method ignores the cases and compares the strings. 6.int compareTo(String):- It is used to compare two strings. -If string1 is greater than String2 this method returns + ve value -If string1 is lesser than string2 then this method returns –ve value. -If string1==string2 this function returns zero. 14 CS 306 Reference No.: R1 SELO: 1,2
  • 15. Ex. if((x.compareTo(y))>0) { System.out.println (“string1 is greater”); } else if(x.compareTo(y))<0) System.out.println (“String2 is greater”); else System.out.println (“both strings are equals”); } 15 CS 306 Reference No.: R1 SELO: 1,2
  • 16. Learning Outcomes • Understand the basic concept in Java • To understand used of Java • Be able to work in Java
  • 17. References 1. Herbert schildt ,”The complete Reference Java” ,TMH publications.