/**
*
* @author ardie
*/
public class KelasString3 {
public static void main(String[] args) {
FungsiManipulasiKarakter call = new FungsiManipulasiKarakter();
call.FungsiSplit();
call.FungsiIndexOf();
call.StringToArray();
}
}
class FungsiManipulasiKarakter {
public void FungsiSplit() {
String str = "one-two-three";
String[] temp;
String delimiter = "-";
temp = str.split(delimiter);
for (int i = 0; i < temp.length; i++) {
System.out.println("Array ke : " + i + ": " + temp[i]);
}
System.out.println("- - - - - - - - - - - - - - -");
}
public void FungsiIndexOf() {
String kata = "Hello world Hello World";
int intIndex = kata.indexOf("Hello");
if (intIndex == -1) {
System.out.println("Hello not found");
} else {
System.out.println("Found Hello at index : " + intIndex);
}
System.out.println("- - - - - - - - - - - - - - -");
}
public void StringToArray() {
String nama = "Ardie Jocong";
char[] stringArray;
stringArray = nama.toCharArray();
for (int index = 0; index < stringArray.length; index++) {
System.out.print(stringArray[index] + " ");
}
System.out.println("\n- - - - - - - - - - - - - - -");
}
}
Output :Array ke : 0: one
Array ke : 1: two
Array ke : 2: three
- - - - - - - - - - - - - - -
Found Hello at index : 0
- - - - - - - - - - - - - - -
A r d i e J o c o n g
- - - - - - - - - - - - - - -
0 comments:
Post a Comment