SlideShare a Scribd company logo
1 of 14
DEFINING STRING
MA’AM KARLA C. VITERBO
In java, string is basically an object that represents
sequence of char values. An array of characters works
same as java string. For example:
char[] ch={'j','a','v','a','_','p','o','i','n','t'};
String s=new String(ch);
is same as:
String s="java_point";
Java String class provides a lot of methods to perform
operations on strings such as compare(), concat(), equals(),
split(), length(), replace(), compareTo(), intern(), substring() etc.
PROGRAMMING CODES
•Char-character
•Public-is a java keyword which declares a
member's access as public. Public members are
visible to all other classes.
•Public members can be accessed from the child class
of the same package. Private members cannot be
accessed from the child class of the same package.
PROGRAMMING CODES
• Void is a return type used for functions in C++.It is used when the
function is not going to return any value. For example:-
lets design a program that just print numbers 1 to n.
Void printnaturalnos(int n){
for(int i=0;i<n;i++){
cout<<i<<" ";
}
}
since ,this function is not returning any value therefore,we have takes its
return type as void.
WHAT IS STRING IN JAVA?
• generally, string is a sequence of characters. but in java,
string is an object that represents a sequence of
characters. the java.lang.string class is used to create a
string object.
• Strings are used for storing text.
A String variable contains a collection of characters
surrounded by double quotes:
In Java, a string is a sequence of characters. For
example, "hello" is a string containing a sequence of
characters 'h', 'e', 'l', 'l', and 'o'.
We use double quotes to represent a string in Java.
For example,
// create a string
String type = "Java programming";
EXAMPLES
Example
Create a variable of type String and assign it a value:
String greeting = "Hello";
public class Main {
public static void main(String[] args) {
String greeting = "Hello";
System.out.println(greeting);
}
}
STRING LENGTH
A String in Java is actually an object, which contain
methods that can perform certain operations on strings.
For example, the length of a string can be found with
the length() method:
Example
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
System.out.println("The length of the txt string is: " +txt.length());
public class main {
public static void main(string[] args) {
string txt = "abcdefghijklmnopqrstuvwxyz";
system.out.println("the length of the txt string
is: " + txt.length());
}
}
THERE ARE TWO WAYS TO CREATE STRING
OBJECT:
1. by string literal - java string literal is created by using double
quotes. for example:
string s="welcome";
2. by new keyword
string s=new string("welcome");//creates two objects and one
reference variable
EXAMPLE
class Main {
public static void main(String[] args) {
// create strings
String first = "Java";
String second = "Python";
String third = "JavaScript";
// print strings
System.out.println(first);// print Java
System.out.println(second); // print Python
System.out.println(third); // print JavaScript
}
}
EXAMPLE
public class Example{
public static void main(String args[]){
//creating a string by java string literal
String str = "Beginnersbook";
char arrch[]={'h','e','l','l','o’};
//converting char array arrch[] to string str2
String str2 = new String(arrch);
//creating another java string str3 by using new keyword
String str3 = new String("Java String Example");
//Displaying all the three strings
System.out.println(str);
System.out.println(str2);
System.out.println(str3);
}
}
OUTPUT
Beginnersbook
hello
Java String Example
https://www.w3schools.com/java/tryjava.asp
?filename=demo_strings

More Related Content

Similar to 1st.pptx

javastringexample problems using string class
javastringexample problems using string classjavastringexample problems using string class
javastringexample problems using string class
fedcoordinator
 

Similar to 1st.pptx (20)

String handling
String handlingString handling
String handling
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Java
JavaJava
Java
 
Java string , string buffer and wrapper class
Java string , string buffer and wrapper classJava string , string buffer and wrapper class
Java string , string buffer and wrapper class
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptx
 
CH1 ARRAY (1).pptx
CH1 ARRAY (1).pptxCH1 ARRAY (1).pptx
CH1 ARRAY (1).pptx
 
Strings in programming tutorial.
Strings  in programming tutorial.Strings  in programming tutorial.
Strings in programming tutorial.
 
String Operations.pptx
String Operations.pptxString Operations.pptx
String Operations.pptx
 
String notes
String notesString notes
String notes
 
Java string handling
Java string handlingJava string handling
Java string handling
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
javastringexample problems using string class
javastringexample problems using string classjavastringexample problems using string class
javastringexample problems using string class
 
Java string handling
Java string handlingJava string handling
Java string handling
 
package
packagepackage
package
 
L14 string handling(string buffer class)
L14 string handling(string buffer class)L14 string handling(string buffer class)
L14 string handling(string buffer class)
 
Programming in scala - 1
Programming in scala - 1Programming in scala - 1
Programming in scala - 1
 
StringBuffer.pptx
StringBuffer.pptxStringBuffer.pptx
StringBuffer.pptx
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
 
Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................
 
Matlab strings
Matlab stringsMatlab strings
Matlab strings
 

Recently uploaded

Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
AroojKhan71
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
amitlee9823
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 

Recently uploaded (20)

Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
ALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptx
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 

1st.pptx

  • 2. In java, string is basically an object that represents sequence of char values. An array of characters works same as java string. For example: char[] ch={'j','a','v','a','_','p','o','i','n','t'}; String s=new String(ch); is same as: String s="java_point"; Java String class provides a lot of methods to perform operations on strings such as compare(), concat(), equals(), split(), length(), replace(), compareTo(), intern(), substring() etc.
  • 3. PROGRAMMING CODES •Char-character •Public-is a java keyword which declares a member's access as public. Public members are visible to all other classes. •Public members can be accessed from the child class of the same package. Private members cannot be accessed from the child class of the same package.
  • 4. PROGRAMMING CODES • Void is a return type used for functions in C++.It is used when the function is not going to return any value. For example:- lets design a program that just print numbers 1 to n. Void printnaturalnos(int n){ for(int i=0;i<n;i++){ cout<<i<<" "; } } since ,this function is not returning any value therefore,we have takes its return type as void.
  • 5. WHAT IS STRING IN JAVA? • generally, string is a sequence of characters. but in java, string is an object that represents a sequence of characters. the java.lang.string class is used to create a string object. • Strings are used for storing text. A String variable contains a collection of characters surrounded by double quotes:
  • 6. In Java, a string is a sequence of characters. For example, "hello" is a string containing a sequence of characters 'h', 'e', 'l', 'l', and 'o'. We use double quotes to represent a string in Java. For example, // create a string String type = "Java programming";
  • 7. EXAMPLES Example Create a variable of type String and assign it a value: String greeting = "Hello"; public class Main { public static void main(String[] args) { String greeting = "Hello"; System.out.println(greeting); } }
  • 8. STRING LENGTH A String in Java is actually an object, which contain methods that can perform certain operations on strings. For example, the length of a string can be found with the length() method: Example String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; System.out.println("The length of the txt string is: " +txt.length());
  • 9. public class main { public static void main(string[] args) { string txt = "abcdefghijklmnopqrstuvwxyz"; system.out.println("the length of the txt string is: " + txt.length()); } }
  • 10. THERE ARE TWO WAYS TO CREATE STRING OBJECT: 1. by string literal - java string literal is created by using double quotes. for example: string s="welcome"; 2. by new keyword string s=new string("welcome");//creates two objects and one reference variable
  • 11. EXAMPLE class Main { public static void main(String[] args) { // create strings String first = "Java"; String second = "Python"; String third = "JavaScript"; // print strings System.out.println(first);// print Java System.out.println(second); // print Python System.out.println(third); // print JavaScript } }
  • 12. EXAMPLE public class Example{ public static void main(String args[]){ //creating a string by java string literal String str = "Beginnersbook"; char arrch[]={'h','e','l','l','o’}; //converting char array arrch[] to string str2 String str2 = new String(arrch); //creating another java string str3 by using new keyword String str3 = new String("Java String Example"); //Displaying all the three strings System.out.println(str); System.out.println(str2); System.out.println(str3); } }