Menu
Question Index
...

What will be the output of the following program?

public class SplitStringByUsingDelimiter
{
    public static void main(String args[])
    {
        String str = "Ram-Robert-Rahim";
        String[] temp;
        String delimiter = "-";
        temp = str.split(delimiter);

        for(int i = 0; i < temp.length ; i++)
        {
            System.out.print(temp[i] + " ");
            str = "Ram.Robert.Rahim";
            delimiter = "\\.";
            temp = str.split(delimiter);
        }
        System.out.println();

        for(int i = 0; i < temp.length ; i++)
        {
            System.out.print(temp[i] + " ");
            temp = str.split(delimiter, 2);
            System.out.println();

            for(int j = 0; j < temp.length ; j++)
            {
                System.out.print(temp[i] + " ");
            }
            System.out.println();
        }
    }
}


Ram Robert Rahim
Ram
Ram Ram
Robert Robert
Rahim Rahim
Ram Robert Rahim
Ram
Ram Ram
Robert.Rahim
Robert.Rahim Robert.Rahim
Ram Robert Rahim
Ram
Ram Ram Ram
Robert
Robert Robert Robert
Rahim
Rahim Rahim Rahim
Compilation Error
Runtime Error

Doubts

Problems

Topic: Additional String Methods in Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App