Which of this method of class 10th is used to extract a substring from a string object?

b) Substring()

c) SubString()

d) None of the mentioned

2. What will s2 contain after following lines of Java code?

 StringBuffer s1 = "one";

StringBuffer s2 = s1.append("two")

a) one

b) two

c) onetwo

d) twoone

3. Which of this method of class StringBuffer is used to reverse sequence of characters?

a) reverse()

b) reverseall()

c) Reverse()

d) reverseAll()

4. Which of this method of class StringBuffer is used to get the length of the sequence of characters?

a) length()

b) capacity()

c) Length()

d) Capacity()

5. Which of the following are incorrect form of StringBuffer class constructor?

a) StringBuffer()

b) StringBuffer(int size)

c) StringBuffer(String str)

d) StringBuffer(int size , String str)

6. What will be the output of the following Java code?

  class output 

  {

    public static void main(String args[])

    { 

       StringBuffer c = new StringBuffer("Hello");

       System.out.println(c.length());

    }

  }

a) 4

b) 5

c) 6

d) 7

7. What will be the output of the following Java code?

 class output 

 {  

   public static void main(String args[]) 

   {  

     StringBuffer sb=new StringBuffer("Hello");  

     sb.replace(1,3,"Java");  

     System.out.println(sb);

   }  

 }

a) Hello java

b) Hellojava

c) HJavalo

d) Hjava

8. What will be the output of the following Java code?

  class output 

  {

    public static void main(String args[])

    { 

      StringBuffer s1 = new StringBuffer("Hello");

      s1.setCharAt(1,'x');

      System.out.println(s1);

    }

  }

a) xello

b) xxxxx

c) Hxllo

d) Hexlo

9. What will be the output of the following Java code?

  class output 

  {

    public static void main(String args[])

    {

      StringBuffer s1 = new StringBuffer("Hello World");

      s1.insert(6 , "Good ");

      System.out.println(s1);

    }

  }

a) HelloGoodWorld

b) HellGoodoWorld

c) HellGood oWorld

d) Hello Good World

10. What will be the output of the following Java code?

  class output 

  {

    public static void main(String args[])

    { 

      StringBuffer s1 = new StringBuffer("Hello");

      s1.insert(1,"Java");

      System.out.println(s1);

    }

  }

a) hello

b) java

c) Hello Java

d) HJavaello

Answer & Explanation

Which of this method of class 10th is used to extract a substring from a string object?
Solved by verified expert

at, ul, consectetur

iciturur laoree

Fusce, consectetu

lestiefacilisis.

iciturac, dictum vitae odio. Donec aliquet.

risusce d

ec facipsum dolo

, dictu, consec

usce duicitur laoreet. Nam

inia pulec facilisis

gue

Unlock full access to Course Hero

Explore over 16 million step-by-step answers from our library

Subscribe to view answer

Step-by-step explanation

leamet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque d

gue

iacongue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dol

gue

acifacilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie co

gue

, cur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac m

gue

dicdictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam

gue

fmolestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsu

gue

remur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec alique

gue

tctum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor

gue

ces a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem

gue

ce dat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum

Which method of class string is used to extract a substring from string?

substring(int beginIndex): This method is used to extract a portion of the string starting from beginIndex.

How can you extract a substring from a given string?

You can extract a substring from a String using the substring() method of the String class to this method you need to pass the start and end indexes of the required substring.

What substring () and substr () will do?

The difference between substring() and substr() substr() 's start index will wrap to the end of the string if it is negative, while substring() will clamp it to 0 . Negative lengths in substr() are treated as zero, while substring() will swap the two indexes if end is less than start .

What is substring method in string?

The substring() method extracts characters, between two indices (positions), from a string, and returns the substring. The substring() method extracts characters from start to end (exclusive). The substring() method does not change the original string.