ืืฉืืื lastIndexOf() ืืืืืจื ืืช ืืืืงืื ืฉื ืืืืคืข ืืืืจืื ืฉื ืชื ืฉืฆืืื ืื ืืืจืืืช ืืฉื ื ืืืืจืืืช. ืชืืจ ืืขืฆืื ืฉืืฉ ืื ืกืื ืฉื ืืงืกื ืืจืื, ืื ืืืชืจ ื ืืื ืฉืืจื ืืจืืื. ืื ืืืื ืืืืืช, ืืืฉื, ืืืชื, ืืืชื ืฆืจืื ืืืฆืื ืืช ืืืงืื ืฉืื ืืชืืฆืขืช ืืฉืืื ืืืืจืื ื ืื ืืขื ืืฉื ืฉืืชื ืืืจ ืืืืจ. ืืืงืจืื ืืืื, ืฉืืืช indexOf ืฉื ืืืืงืช Java String ืืชืืืื ืืืื. ืื ืืชื ืฆืจืื ืืช ืืืืคืขื ืืจืืฉืื ื ืฉื ืชื ืืืืจืืืช, ืืชื ืืืื ืืืฉืชืืฉ ืืฉืืืช indexOf() , ืืื ืืืื ืืืื ื- lastIndexOf() . ืืฉื ื ืืจืืข ืืจืกืืืช ืฉื ืฉืืืช lastIndexOf() . ืืจืืข ืฉืืืืช ืขื ืืืชื ืฉื ืื ืคืจืืืจืื ืฉืื ืื ืืคืฉืจืืื ืขืงื ืขืืืก ืืชืจ ืฉื ืืฉืืื. ืืืื ื ืกืชืื ืขื ืื ืืจืืข ืืืืจืืืฆืืืช ืฉื ืฉืืื ืื ืขื ืืืืืืืช.
lastIndexOf(int ch)
ืฉืืื ืื ืืืืืจื ืืช ืืืื ืืงืก ืฉื ืืืืคืข ืืืืจืื ืฉื ืืชื ืืจืฆืฃ ืืชืืืื.ืชืืืืจ ืฉื ืืฉืืื
int lastIndexOf(int ch)
ืคืจืืืจ: ch : ืชื.
ืืืืื ืืงืื
public class LastIndexOf1 {
public static void main(String args[])
{
//letter to find index in String
char letter = 'd';
//String to find an index of a letter
String myString = "This is major Tom to ground control, do you copy";
//The index of last appearance of d will be printed
System.out.println("Last Index of d = " + myString.lastIndexOf(letter));
}
}
ืืคืื ืืื:
ืืื ืืงืก ืืืจืื ืฉื d = 37
ืื ืืชื ืฉืื ื ืืืคืฉืื ืืื ื ื ืืฆื ืืืืจืืืช ืฉืื ื, ืืฉืืื ืืืืืจื -1:
public class LastIndexOf1 {
public static void main(String args[])
{
char letter = 'z';
String myString = "This is major Tom to ground control, do you copy";
System.out.println("Last Index of z = " + myString.lastIndexOf(letter));
}
}
ืืคืื ืืื:
ืืื ืืงืก ืืืจืื ืฉื z = -1
lastIndexOfโ(int ch, int fromIndex)
lastIndexOf(int ch, int fromIndex) : ืื ืชื ืื ืืืืฆื ืืืืจืืืช, ืฉืืื ืื ืืืืืจื ืืช ืืืื ืืงืก ืฉื ืืืืคืข ืืืืจืื ืฉื ืืชื ch, ืชืื ืืืคืืฉ ืืืืจื ืืื ืืืื ืืงืก ืฉืฆืืื. ืื ืชื ืื ืืื ื ืืืืฆื ืืืืจืืืช ืืฉื ื, ืืื ืืืืืจ -1.ืชืืืืจ ืฉื ืืฉืืื
public int lastIndexOf(int ch, int fromIndex)
ืคืจืืืจืื: ch : ืชื. fromIndex : ืืืื ืืงืก ืฉืืื ื ืืชืืืืื ืืช ืืืืคืืฉ.
ืืืืืืืช ืงืื ืฉื lastIndexOf(int ch, int fromIndex)
public class LastIndexOf2 {
public static void main(String args[])
{
//letter to find index in String
char letter = 'o';
//String to find an index of a letter
String myString = "This is major Tom to ground control, do you copy";
//The index of last appearance of o before 20th symbol will be printed
System.out.println("Last Index of o = " + myString.lastIndexOf(letter, 20));
}
}
ืืคืื ืืื:
ืืื ืืงืก ืืืจืื ืฉื o = 19
ืื ืืืขืืจ ืืืืื ืืงืก ืืชืืืืช ืืฉืืจื ืื ื ืชืงืืื ืืชื, ืืฉืืื ืชืืืืจ -1:
public class LastIndexOf2 {
public static void main(String args[])
{
char letter = 'o';
String myString = "This is major Tom to ground control, do you copy";
System.out.println("Last Index of o = " + myString.lastIndexOf(letter, 10));
}
}
ืืคืื ืืื:
ืืื ืืงืก ืืืจืื ืฉื o = -1
lastIndexOf(String str)
lastIndexOf(String str) : ืืจืืืฆืื ืื ืฉื ืืฉืืื ืืงืืืช ืืืจืืืช ืืืจืืืื ื ืืืืืืจื ืืช ืืืื ืืงืก ืืชืื ืืืจืืืช ืื ืฉื ืืืืคืขื ืืจืืฉืื ื ืฉื ืืืืจืืืช ืืืฉื ื ืฉืฆืืื ื. ืื ืื ืื ืืืคืืข ืืืืจืืืช ืืฉื ื, ืืฉืืื ืืืืืจื -1.ืชืืืืจ ืฉื ืืฉืืื
public int lastIndexOf(String str)
ืคืจืืืจืื: str : ืืืจืืืช.
ืืืืืืืช ืงืื ืฉื lastIndexOf(String str)
public class LastIndexOf3 {
public static void main(String args[])
{
String myString = "This is major Tom to ground control, do you copy";
System.out.println( myString.lastIndexOf("Tom"));
}
}
ืืคืื ืืื:
14
ืื ืืื ืืืจืืืช ืืฉื ื ืืื, ืืฉืืื ืืืืืจื -1. ืืืื ื ื ืกื ืืืฆืื ืืื ืืงืก ืฉื ืชืืืืช ืืืืจืืืช ืืืฉื ื "tom".
public class LastIndexOf3 {
public static void main(String args[])
{
String myString = "This is major Tom to ground control, do you copy";
System.out.println( myString.lastIndexOf("tom"));
}
}
ืืืืจ ืฉ-"T" ื-'t" ืื ืกืืืื ืฉืื ืื, ืืืื ืืื "ืืื" ืืืืจืืืช ืืื. ืื ื ืืคืื:
-1
lastIndexOf(String str, int fromIndex)
lastIndexOf(String str, int fromIndex) . ืืจืืื ื ืื ืฉื ืืฉืืื ืืืืืจ ืืช ืืืื ืืงืก ืืชืื ืืืจืืืช ืื ืฉื ืืืืคืขื ืืืืจืื ื ืฉื ืืืืจืืืช ืืืฉื ื ืฉืฆืืื ื, ืืืคืืฉ ืืืืจื ืืื ืืืื ืืงืก ืฉืฆืืื.ืชืืืืจ ืฉื ืืฉืืื
public int lastIndexOf(String str, int beg)
ืคืจืืืจืื str : ืืืจืืืช. fromIndex : ืืืื ืืงืก ืฉืืื ื ืืชืืืืื ืืช ืืืืคืืฉ.
ืืืืืืืช ืงืื ืฉื lastIndexOf(String str, int fromIndex)
ืืืื ื ื ืกื ืืืฆืื ืืช ืืืื ืืงืก ืฉื ืืืืคืขื ืืืืจืื ื ืฉื ืชืช ืืืืจืืืช "ro" ืืืืจืืืช "ืืื ืืื ืขืืงืจื ืืืงืจืช ืงืจืงืข, ืืื ืืชื ืืขืชืืง". ืืคืขื ืืจืืฉืื ื ื ืขืืืจ ืขื ืื ืืืืจืืืช, ืืคืขื ืืฉื ืืื ื ืชืืื ืืืชื ืขื ืืื ืืงืก 25 (ืืืืืจ, ืขื ืืืืืืฅ ืืขืืืื, ืืืืคืืฉ ืืืจ ืืืื ืืงืก ืขืืืจ ืืืกืืฃ ืืืชืืื).public class LastIndexOf4 {
public static void main(String[] args) {
String myString = "This is major Tom to ground control, do you copy";
System.out.println( myString.lastIndexOf("ro"));
System.out.println(myString.lastIndexOf("ro",25));
}
}
ืืคืื ืืื:
32 22
ืงืจืืื ื ืืกืคืช: |
---|
GO TO FULL VERSION