Dt : 3/7/2022
define toUpperCase()?
=>toUpperCase() method is used to convert the given String
into UpperCase format.
define toLowerCase()?
ii
=>toLowerCase() method is used to convert the given String
ath
into LowerCase format.
aip
define substring() method?
=>substring() method is used to take the part of String based
hM
on index values.
Method Signatures:
tes
public java.lang.String substrint(int);
public java.lang.String substring(int,int);
a
nk
faq:
wt is the diff b/w
Ve
(a)break
(b)continue
(c)return
(d)exit
(a)break:
=>'break' statement is used to stop switch-case execution
and also used to stop Iterative Statements based on condition.
(b)continue:
=>'continue' statement is used to skip the lines from the
ii
iteration based on condition.
ath
=>The lines which are declared below the 'continue' statement
will be skipped.
(c)return:
aip
hM
=>'return' statement is used to return the value after method
execution in return_type methods.
tes
(d)exit:
=>'exit' is used to stop the program execution.
a
syntax:
nk
System.exit(0);
Ve
Ex : DemoString8.java
package maccess;
import java.util.*;
public class DemoString8 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter the String1(min length
10):");
String str1 = s.nextLine().trim();
System.out.println("Enter the String2(min length
10):");
String str2 = s.nextLine().trim();
System.out.println("====equals()====");
boolean k = str1.equalsIgnoreCase(str2);
if(k) {
System.out.println("Strings are equal...");
}else {
System.out.println("Strings are Not-Equal...");
}
System.out.println("====compareTo()====");
ii
int z = str1.compareToIgnoreCase(str2);
if(z==0) {
ath
System.out.println("Strings are equal...");
}else {
System.out.println("Strings are Not-Equal...");
}
System.out.println("=====substring()====");
aip
String s1 = str1.substring(4);
System.out.println("s1:"+s1.toString());
String s2 = str1.substring(2,6);
System.out.println("s2:"+s2.toString());
hM
System.out.println("====break====");
for(int i=1;i<=20;i++)
{
if(i==12)
{
tes
break;//stop the loop
//System.exit(0);
}
System.out.print(i+" ");
}//end of loop
a
System.out.println("\n====continue====");
nk
for(int i=65;i<=90;i++)
{
char ch = (char)i;//ASCII to char
if(ch=='A' || ch=='E' || ch=='I' || ch=='O' ||
Ve
ch=='U')
{
continue;//skip the below line
}
System.out.print(ch+" ");
}//end of loop
s.close();
}
}
o/p:
Enter the String1(min length 10):
java language
Enter the String2(min length 10):
java language
====equals()====
ii
Strings are equal...
ath
====compareTo()====
Strings are equal...
aip
=====substring()====
s1: language
hM
s2:va l
====break====
1 2 3 4 5 6 7 8 9 10 11
tes
====continue====
BCDFGHJKLMNPQRSTVWXYZ
a
=================================================
nk
Assignment:
wap to display the numbers from 1 to 100,but skip prime numbers?
Ve
define prime number?
=>The number which is having only two factors 1 and itself is
known as Prime number.
====================================================
faq:(Java13 - new feature)
define switch-case-yield statement?
=>switch-case-yield statement introduced by Java13 version
and which is used to return the value,which means return_type
switch.
ii
structure:
ath
return switch(value)
aip
case 1 : yield result;
case 2 : yield result;
hM
...
case n : yield result;
default: yield default_value;
tes
};
a
=>In switch-case-yield declaring 'default' is manditory.
nk
=>'yield' specify to stop the switch-case executiob and return
the result.
Ve
===========================================================
Note:
=>'trim()' method is used to remove the spaces before and after
the Strings.
=>'IgnoreCase' specify compare the content of an objects by
not considering the case.
==========================================================
(iii)Using 'is equal to'(==) operator:
=>'is equal to' operator will compare the references of
an Objects and which will not compare the content of an objects.
=>'is equal to'(==) operator is not preferable to use on
ii
NonPrimitive DataType variables,because generate Wrong results.
ath
Ex : DemoString9.java
aip
package maccess;
public class DemoString9 {
public static void main(String[] args) {
int a=10;//Primitive data type variable
hM
int b=10;//Primitive data type variable
String s1 = new String("java");//NonPrimitive
String s2 = new String("java");//NonPrimitive
String s3 = "program";//NonPrimitive
String s4 = "program";//NonPrimitive
System.out.println("*****Primitive DataType
tes
Values****");
if(a==b) {
System.out.println("Values are equal...");
}else {
a
System.out.println("Values are Not-Equal...");
}
nk
System.out.println("****NonPrimitive DataType
Values****");
System.out.println("(new operator process)");
Ve
if(s1==s2) {
System.out.println("Strings are equal...");
}else {
System.out.println("Strings are Not-Equal...");
}
System.out.println("****NonPrimitive DataType
Values****");
System.out.println("(String literal process)");
if(s3==s4) {
System.out.println("Strings are equal...");
}else {
System.out.println("Strings are Not-Equal...");
}
}
}
o/p:
*****Primitive DataType Values****
ii
Values are equal...
ath
****NonPrimitive DataType Values****
(new operator process)
Strings are Not-Equal...
****NonPrimitive DataType Values****
(String literal process)
aip
hM
Strings are equal...
==================================================
faq:
tes
define String Constant pool?
=>The separate partition of HeapArea where String objects are
a
nk
created is known as String Constant Pool.
Ve
Behaviour:
=>String Constant pool will retrict the duplicate String
Objects creation.(Only unique String Objects are created)
========================================================