Log In Register

Units


Java String - Questions and Answers

 

Practice these Java String under Java Programming walk-in interview Questions/ examination questions with best tricks and short cuts with solution. Student (candidate) who want to crack the walk in interview, competitive exams and want to find short cuts and tricks to solve questions on Java String for following purpose.


– Anyone who is wishing to increase their perfect knowledge of Java String of Java Programming.
– Anyone who is preparing for aptitude test and increase his in depth aptitude knowledge Java Programming specifically Java String.
– Anyone who is preparing for interviews (competitive examinations, govt examinations and bank examinations, off-campus or on campus interviews, walk-in interview and company interviews) having questions on Java String under Java Programming.

– Anyone who is preparing for aptitude test or competitive exam or entrance exam.
– Anyone who is preparing for entrance examinations and other competitive examinations.
– All Experienced, Freshers and Students.

Here is list of Questions and Answers covering all key area of  Java String topic of Java Programming:

 

1.
String str1 = "Kolkata".replace('k', 'a');

In the above statement, the effect on string Kolkata is 

Answer: Option B

Explanation:

replace() method returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
Syntax: Here is the syntax of this method:
public String replace(char oldChar, char newChar)
Parameters: Here is the detail of the parameters:
oldChar -- the old character. newChar -- the new character.
Return Value: It returns a string derived from this string by replacing every occurrence of oldChar with

2.

What could be output of the following fragment of code?

public class Test{
        public static void main(String args[]){ 
		String x = "hellow";
		int y = 9;
		System.out.println(x += y);
        } 
}

Answer: Option B

Explanation:

3. What will be the output of the following program? public class Test{ public static void main(String args[]){ String str1 = "one"; String str2 = "two"; System.out.println(str1.concat(str2)); } }

Answer: Option C

Explanation:
Concat() method appends one String to the end of another. The method returns a String with the value of the String passed into the method appended to the end of the String which is used to invoke this method.

4. Determine output: public class Test{ public static void main(String args[]){ String str = null; if(str.length() == 0){ System.out.print("1"); } else if(str == null){ System.out.print("2"); } else{ System.out.print("3"); } } }

Answer: Option D

Explanation:

5. Which of these constructors is used to create an empty String object?

Answer: Option A

Explanation:

6. Which of these method of class String is used to check weather a given object starts with a particular string literal?

Answer: Option A

Explanation:
Method startsWith() of string class is used to check whether the String in question starts with a specified string. It is specialized form of method regionMatches()

7.

What will be the output?

1. public class Test{
2.      public static void main(String args[]){
3.            Object myObj = new String[]{"one", "two", "three"};
4.            {
5.	          for(String s : (String[])myObj) 
6.		        System.out.print(s + ".");
7.	    }
8.      }
9. }

Answer: Option A

Explanation:

8. Which of the following statements are incorrect?

Answer: Option B

Explanation:
Strings in Java are immutable that is they can not be modified.

9. Which of these method of class String is used to extract a single character from a String object?

Answer: Option C

Explanation:

10. Which of these is an oncorrect statement?

Answer: Option C

Explanation:
StringBuffer class is used to create strings that can be modified after they are created.

11.

What will be the output?

String str1 = "abcde";
System.out.println(str1.substring(1, 3));

Answer: Option B

Explanation:

substring() method has two variants and returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string or upto endIndex - 1 if second argument is given.
Syntax: Here is the syntax of this method:
public String substring(int beginIndex)
or
public String substring(int beginIndex, int endIndex)
Parameters: Here is th

12.

What will be output?

String S1 = "S1 ="+ "123"+"456";
String S2 = "S2 ="+(123+456);

Answer: Option A

Explanation:

If a number is quoted in "" then it becomes a string, not a number any more.

13. Which of these method of class String is used to compare two String objects for their equality?

Answer: Option A

Explanation:

14.  Which of these class is superclass of String and StringBuffer class?

Answer: Option B

Explanation:

15. What could be output of the following fragment of code? public class Test{ public static void main(String args[]){ String x = "hellow"; int y = 9; System.out.println(x += y); } }

Answer: Option B

Explanation: