SlideShare a Scribd company logo
1 of 15
Java
Strings
String
 Declaration of String
 String s1;
 Declare and Initialize a String
 String s2 = “SIKANDER”;
Length of String
 String name = “SIKANDER”;
 int len = name.length( );
 Output : 8
Accessing Individual Elements of
String
 charAt(int index);
String Assignment
String Concatenation
 +
Compare String
String s1 = "ABCD”;
String s2 = "ABCD”;
if(s1 == s2)
System.out.println("Equal");
else
System.out.println("NOT Equal");
In Java, when the“==” operator is used
to compare2 objects, it checks to see if
the objects refer to the same place in
memory.
String s1 = new String("ABCD”);
String s2 = new String("ABCD”);
if(s1 == s2)
System.out.println("Equal");
else
System.out.println("NOT Equal");
 To check if strings have same data, use
equals
 String s1 = new String("ABCD");
 String s2 = new String("ABCD");

 if(s1.equals(s2))
 System.out.println("Equal");
 else
 System.out.println("NOT Equal");
String Concatination
 System.out.println(3 + 5);
 System.out.println(3 + 5 + "abcd");
 System.out.println("abcd" + 3 + 5);
 System.out.println("abcd" + 3 * 5);
 What is the output of these
statements?
String str = "SIKANDER”;
System.out.println(str);
System.out.println(str.toLowerCase());
String str = "SIKANDER”;
System.out.println(str);
str.toLowerCase();
System.out.println(str);
String str = "SIKANDER”;
System.out.println(str.hashCode());
str = str.toLowerCase();
System.out.println(str.hashCode());
https://www.hackerrank.com/challenges/camel
case
https://www.hackerrank.com/challenges/pangr
ams
Count Number of Unique Characters
https://www.hackerrank.com/challenges/string-
construction

More Related Content

What's hot (20)

javathreads
javathreadsjavathreads
javathreads
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
String Handling
String HandlingString Handling
String Handling
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Regular Expressions in Java
Regular Expressions in JavaRegular Expressions in Java
Regular Expressions in Java
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
 
String in java
String in javaString in java
String in java
 
Java awt
Java awtJava awt
Java awt
 
Java String
Java String Java String
Java String
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
 
input/ output in java
input/ output  in javainput/ output  in java
input/ output in java
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
Java arrays
Java arraysJava arrays
Java arrays
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
 

Viewers also liked

05 Java Language And OOP Part V
05 Java Language And OOP Part V05 Java Language And OOP Part V
05 Java Language And OOP Part VHari Christian
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in javaHitesh Kumar
 
Arrays string handling java packages
Arrays string handling java packagesArrays string handling java packages
Arrays string handling java packagesSardar Alam
 
String java
String javaString java
String java774474
 
Java string handling
Java string handlingJava string handling
Java string handlingSalman Khan
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
 
String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)Anwar Hasan Shuvo
 

Viewers also liked (9)

05 Java Language And OOP Part V
05 Java Language And OOP Part V05 Java Language And OOP Part V
05 Java Language And OOP Part V
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Strings
StringsStrings
Strings
 
Arrays string handling java packages
Arrays string handling java packagesArrays string handling java packages
Arrays string handling java packages
 
String java
String javaString java
String java
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)
 
Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674
 

Similar to Java strings

Similar to Java strings (20)

String functions
String functionsString functions
String functions
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
 
Java Small Tests
Java Small TestsJava Small Tests
Java Small Tests
 
Java - Strings Concepts
Java - Strings ConceptsJava - Strings Concepts
Java - Strings Concepts
 
Text processing
Text processingText processing
Text processing
 
13 Strings and text processing
13 Strings and text processing13 Strings and text processing
13 Strings and text processing
 
String and string manipulation
String and string manipulationString and string manipulation
String and string manipulation
 
Strings.ppt
Strings.pptStrings.ppt
Strings.ppt
 
Day_5.1.pptx
Day_5.1.pptxDay_5.1.pptx
Day_5.1.pptx
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
 
07slide
07slide07slide
07slide
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Strings and Characters
Strings and CharactersStrings and Characters
Strings and Characters
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Module-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdfModule-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdf
 
Detailed description of Strings in Python
Detailed description of Strings in PythonDetailed description of Strings in Python
Detailed description of Strings in Python
 
8. String
8. String8. String
8. String
 
Java™ (OOP) - Chapter 9: "Strings and Text I/O"
Java™ (OOP) - Chapter 9: "Strings and Text I/O"Java™ (OOP) - Chapter 9: "Strings and Text I/O"
Java™ (OOP) - Chapter 9: "Strings and Text I/O"
 
Chapter 11 Strings.pptx
Chapter 11 Strings.pptxChapter 11 Strings.pptx
Chapter 11 Strings.pptx
 

More from Mohammed Sikander (20)

Operator Overloading in C++
Operator Overloading in C++Operator Overloading in C++
Operator Overloading in C++
 
Python_Regular Expression
Python_Regular ExpressionPython_Regular Expression
Python_Regular Expression
 
Modern_CPP-Range-Based For Loop.pptx
Modern_CPP-Range-Based For Loop.pptxModern_CPP-Range-Based For Loop.pptx
Modern_CPP-Range-Based For Loop.pptx
 
Modern_cpp_auto.pdf
Modern_cpp_auto.pdfModern_cpp_auto.pdf
Modern_cpp_auto.pdf
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Python tuple
Python   tuplePython   tuple
Python tuple
 
Python strings
Python stringsPython strings
Python strings
 
Python set
Python setPython set
Python set
 
Python list
Python listPython list
Python list
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
 
Pointer basics
Pointer basicsPointer basics
Pointer basics
 
Signal
SignalSignal
Signal
 
File management
File managementFile management
File management
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
 
Java arrays
Java    arraysJava    arrays
Java arrays
 
Java notes 1 - operators control-flow
Java notes   1 - operators control-flowJava notes   1 - operators control-flow
Java notes 1 - operators control-flow
 

Recently uploaded

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

Java strings

Editor's Notes

  1. EQUAL
  2. public class StringAssignment { public static void main(String [] args) { String src = "SIKANDER"; String dest; dest = src; System.out.println(dest); System.out.println(src.hashCode() +" " + dest.hashCode()); dest = "BANGALORE"; System.out.println(src.hashCode() +" " + dest.hashCode()); } }
  3. public class StringConcatenation { public static void main(String [] args) { String firstName = "MOHAMMED"; String lastName = "SIKANDER"; String fullName = firstName + lastName; System.out.println("First Name : " + firstName); System.out.println("Last Name : " + lastName); System.out.println("Full Name : " + fullName); } }
  4. NOT EQUAL
  5. NOT EQUAL
  6. 8 8abcd Abcd35 abcd15
  7. First case print in lowercase Second one prints in Uppercase as str is not modified.
  8. import java.util.Scanner; public class StringConcatenation { public static void main(String [] args) { Scanner in = new Scanner(System.in); System.out.println("Enter the input String "); String s = in.next(); in.close(); int len = s.length(); int numberOfUpperCase = 1; for(int i = 0 ; i < len ; i++) { //Access Individual Character char c = s.charAt(i); //Check if its uppercase character. if(Character.isUpperCase(c) == true) { numberOfUpperCase++; } } System.out.println("Number of Uppercase characters : " + numberOfUpperCase); int numberOfWords = numberOfUpperCase + 1; System.out.println("Number of words = " + numberOfWords); } }
  9. import java.util.Scanner; public class Pangram { static int countUniqueCharacters(String sentence) { int lenOfSentence = sentence.length(); boolean [] alphabetFound = new boolean[26]; for(int i = 0 ; i < lenOfSentence ; i++){ if(sentence.charAt(i)!= ' '){ alphabetFound[ sentence.charAt(i) - 'a' ] = true; } } int uniqueCharacters = 0; for(int i = 0 ; i < 26 ; i++) if(alphabetFound[i] == true) uniqueCharacters++; return uniqueCharacters; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); for(int a0 = 0; a0 < n; a0++){ String sentence = in.next(); int uniqueCharacters = countUniqueCharacters(sentence); System.out.println(uniqueCharacters); } } }