How to split a String in ANDROID?

By | May 5, 2011

Hi all…..
Splitting a string in android is really easy.checkout the following snippet.

package com.coderzheaven;

import android.os.Bundle;

public class SplitStringDemo extends Activity {
    String str = "India, USA, Japan, Russia, France";
    public void onCreate(Bundle savedInstanceState) {
        String arr[] = str.split(",");
        for(int i = 0; i < arr.length; i++){
        	System.out.println("arr["+i+"] = " + arr[i].trim());

Check the Logcat for output.
Note: Make sure to put the escape character before the delimiter for splitting,otherwise the output may be each character.

Leave a Reply

Your email address will not be published.