رد: شرح كافة ميثود الـ String الموجودة في السلايدز + بالإضافة لأمثلة
"
و ع ـليكمـ السلامـ ورح ـمة الله وبركاتهـ..
يع ـطيكـٍ الع ـآفيةة أسووومـ..و سلآمتكـٍ ع ـيوونكـٍ ..مآتشووفي ششر يآآرب..:$
"
شآهي أخ ـضر..هذآ الكلآمـ نسخ ـتهـ لكـٍ..
package Exam;
public class Explain {
public static void main(String[] args) {
String name1= "shoroog";
char d=name1.charAt(3); // it will return character so we will declare a variable from type char
System.out.println(d); // it will print the letter at index 3
int f=name1.compareTo("sesraa");
System.out.println(f); // A string is less than another if it comes before the other in dictionary order.
// A string is greater than another if it comes after the other in dictionary order.
// here it will return a positive number because in the dictionary order the "se" comes before "sh"
int w=name1.compareTo("tsraa");
System.out.println(w); // it will return negative number because the letter "t" comes before "s"
int k = name1.compareTo(name1);
System.out.println(k); // it will return zero because we compare name by it self and the are equal
System.out.println(name1.concat(" esraa")); // it will join the two names , it is like the + operator
boolean e=name1.equals("Shoroog");
System.out.println(e);// it will return false because the name1 start with small letter but "Shoroog" Start with Capital letter
boolean y=name1.equalsIgnoreCase("Shoroog");
System.out.println(y);// it will return true because the case is ignored so it will be equal
int l=name1.length(); // it will return the length , and if you want to compute length you shoud start from one because it is not indices
System.out.println(l);
System.out.println("esraa".length());// you can use method string by other way like this ^^ , you declare a string variable by double qutation
System.out.println(name1.indexOf('o'));//it will return the index of the first occurance of letter o
System.out.println(name1.lastIndexOf("o"));//ا it will return the index of the last occurance of letter o
System.out.println(name1.toUpperCase()); // it will be converted to Uppercase
System.out.println("ESRAA".toLowerCase()); // it will be converted to lowercase
System.out.println(name1.substring(3));// it will print the string variable starting from index 3 to the end
System.out.println(name1.substring(3,6));//it will print the سtring variable starting from the start index until reach
// the index 5 , so here the end index will not printed
System.out.println(name1.replace('o', 'w')); // this method will change all the letter o in "shoroog" to be "shwrwwg"
System.out.println(" esraa hamad".trim()); // it will delete " المسافة البادئة " يعني الفراغات اللي تكون زيادة في بداية الجملة
}
}
"
بـ التووفيق..
"
|