Split a String into a String Array
 
Splitting a thing is a very useful thing.
It splits a String at a specific char.

Example 1:
String mystring = "Hello World";
String helloworld[] = mystring.split("");
//This will Split mystring into:
//helloworld[0] = "Hello";
//and: helloworld[1] = "World";


Example 2:
public class test {
  public test() {
  }

  public static void main(String[] args) {
    test test = new test();
    String pplrow = "Carl;Marc;Peter;Mikel";
    String pplarray[] = pplrow.split(";");

    System.out.println(pplarray[2]);
    //This Will give the following output: "Peter"
  }
}


You can also split a string with a StringTokenizer (I personally prefer this solution):

Example 3:
String test="one;two;three;";
StringTokenizer stk=new StringTokenizer(test,";");
String[] stringarray=new String[stk.countTokens()];
int counter=0;

while(stk.hasMoreTokens()) {
stringarray[counter++]=stk.nextToken();
}
//Result: stringarray[0]="one" stringarray[1]="two" stringarray[2]="three"
 
admin / Nov 02, 2003
   
 
 
Login: 
Pass: 
 
 
     
     
2004 - 2019 / lookass.ch
makememad@lookass.ch