368). Which of these methods is used to compare a specific region inside a string with another specific region in another string?

[A]regionMatch()
[B] match()
[C]RegionMatches()
[D]regionMatches()

Show Answer

369). Which of these methods of class String is used to check whether a given object starts with a particular string literal?

[A]startsWith()
[B]endsWith()
[C]Starts()
[D] ends()

Show Answer

370). What is the value returned by function compareTo() if the invoking string is less than the string compared?

[A]zero
[B] value less than zero
[C] value greater than zero
[D]none of the mentioned

Show Answer

371). Which of these data type value is returned by equals() method of String class?

[A]char
[B]int
[C]boolean
[D]all of the mentioned

Show Answer

372). What will be the output of the following Java code?
    class output 
    {
        public static void main(String args[])
        { 
           String c = "Hello i love java";
           boolean var;
           var = c.startsWith("hello");
           System.out.println(var);
        }
    }

[A]true
[B]false
[C]0
[D]1

Show Answer

373). What will be the output of the following Java code?
    class output 
    {
        public static void main(String args[])
        { 
           String s1 = "Hello i love java";
           String s2 = new String(s1);
           System.out.println((s1 == s2) + " " + s1.equals(s2));
        }
    }

[A]true true
[B]false false
[C]true false
[D] false true

Show Answer

374). What will be the output of the following Java code?
    class output 
    {
        public static void main(String args[])
        { 
           String s1 = "Hello";
           String s2 = new String(s1);
           String s3 = "HELLO";
           System.out.println(s1.equals(s2) + " " + s2.equals(s3));
        }
    }

[A]true true
[B] false false
[C]true false
[D] false true

Show Answer

375). In the following Java code, which code fragment should be inserted at line 3 so that the output will be: “123abc 123abc”?
 1. StringBuilder sb1 = new StringBuilder("123");
 2. String s1 = "123";
 3.  // insert code here
 4. System.out.println(sb1 + " " + s1);

[A]sb1.append(“abc”); s1.append(“abc”);
[B]sb1.append(“abc”); s1.concat(“abc”);
[C]sb1.concat(“abc”); s1.append(“abc”);
[D]sb1.append(“abc”); s1 = s1.concat(“abc”);

Show Answer

376). What will be the output of the following Java code?
    class output 
    {
        public static void main(String args[])
        {
             String chars[] = {"a", "b", "c", "a", "c"};
             for (int i = 0; i < chars.length; ++i)
                 for (int j = i + 1; j < chars.length; ++j)
                     if(chars[i].compareTo(chars[j]) == 0)
                         System.out.print(chars[j]); 
        }
   }

[A]ab
[B]bc
[C]ca
[D]ac

Show Answer