0% found this document useful (0 votes)
30 views2 pages

String Methods

The document is a Java program that demonstrates various string manipulation functions, including comparison, extraction, and conversion of strings. It showcases methods such as equals, equalsIgnoreCase, startsWith, endsWith, substring, and valueOf for different data types. The program includes commented-out print statements that illustrate the usage of these functions with example strings.

Uploaded by

saifalhomimat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

String Methods

The document is a Java program that demonstrates various string manipulation functions, including comparison, extraction, and conversion of strings. It showcases methods such as equals, equalsIgnoreCase, startsWith, endsWith, substring, and valueOf for different data types. The program includes commented-out print statements that illustrate the usage of these functions with example strings.

Uploaded by

saifalhomimat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

package stringfunc;

public class Stringfunc {


public static void main(String[] args) {
//1.comaprison functions boolean/ contenets of Strings/ 5 functions
String s="Jordan";
// System.out.println(s.equals("JORDAN"));// ‫ حالة الحرف‬capital small (false)
s.equals(" ")
// System.out.println(s.equals("Jordan"));// ‫ حالة الحرف‬capital small (false)
s.equals(" ") true
//System.out.println(s.equalsIgnoreCase("jordan"));// ‫ ما بفرق اذا كان الحرف‬captial
or small true
//System.out.println(s.equalsIgnoreCase("Jordan"));// ‫ ما بفرق اذا كان الحرف‬captial
or small true
// System.out.println(s.startsWith("jo"));//‫ تاخد حالة الحرف بعين االعتبار‬false
// System.out.println(s.startsWith("Jo"));//true
// System.out.println(s.endsWith("AN")); //‫المقارنة بتكون بالنهاية بتاخد خالة الحرف‬
‫بعين االعتبار‬false
// System.out.println(s.endsWith("an"));//true

String s2="Hashemite Universtity"; //Hash


String s3="Hashemite universtity";
String s4="hashemite universtity";//hash
// regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int
lenght)
// System.out.println(s2.regionMatches(true,0, s3, 0, 4));// ‫اتجاهل حالة الحرف النو‬
‫ اول‬parameter ‫ كان‬true (true)
// System.out.println(s2.regionMatches(false,0, s4, 0, 4));//‫ يفرق‬captital ‫ عن‬small
false
//System.out.println(s2.regionMatches(true,0, s3, 1, 4));
//System.out.println(s2.regionMatches(0, s4, 0, 4));// ‫حالة الحرف ماخوذة بعين‬
‫االعتبار‬
// System.out.println("***************************************");
//String Length, Characters, and Combining Strings function
String str1="Welcome";
String str2=" to Summer Semester ";
// System.out.println(str1.length()); //‫ عدد االحرف اللي في‬string 7
// System.out.println(str1.charAt(3));//c
//System.out.println(str1.charAt(7));
// System.out.println(str1.concat(" to java class"));//+//weclome to java class
// System.out.println(str1.concat(str2));//welcome to summer Semester
// System.out.println("***************************************");
//3.Extracting String function
String sr1 = "Welcome to Java";
//startindex end-1[0-10]
String sr2 = sr1.substring(0, 11) + "HTML";// Welcome to HTML
// System.out.println(sr2);
//start index-to the end ot String
// System.out.println(sr1.substring(11));//Java
/*
System.out.println("Welcome".toLowerCase()); //all letters to small letters
System.out.println("Welcome".toUpperCase());
System.out.println(" Welcome ".trim());//cut white spaces from both start and end
of str...
System.out.println(" Welo cme ".trim());//Welo cme
System.out.println("Welcome".replace('e', 'A') );// ‫ اي‬e ‫' بتالقي بتغيرو‬A' WAlcomA
System.out.println("Welcome".replaceFirst("e", "AB") );//WABlcome ‫اول وحدة بتالقيها‬
System.out.println("Welcome".replace("e", "AB") );//ًWABlcomAB
System.out.println("Welcome".replace("el", "AB") );//WABcome
*/
System.out.println("***************************************");
//Coverting from char ,int , array of char , long to String
System.out.println(String.valueOf(5.44));//double =>String "5.44"
System.out.println(String.valueOf(6));//int => String "6"
char ch[]={'a','m','b'};
String stt=String.valueOf(ch);//array of character to string "amb"
System.out.println(stt);//amb
long l=789456;
String lo=String.valueOf(l);//long to String
System.out.println(lo);// "789456"
System.out.println("***************************************");

You might also like