📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    Consider the following Java code: import

    java.util.Arrays; public class Splitter {     public static void main(String[] args) {         String data = "item1::value1::item2::value2";         String[] parts = data.split("::");         System.out.println(parts.length + " " + parts[1]);     } } What will be the output of this program?
    A 4 value1 Correct Answer Incorrect Answer
    B 2 value1 Correct Answer Incorrect Answer
    C 4 item1 Correct Answer Incorrect Answer
    D 2 item2 Correct Answer Incorrect Answer
    E Compile-time error Correct Answer Incorrect Answer

    Solution

    Correct Answer: A (The string is split by "::". The parts are "item1", "value1", "item2", "value2". So parts.length is 4. parts[1] is "value1".)

    Practice Next
    ask-question