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 in Java is a?

Answer: Option A

Explanation:

2. 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 the detail of parameters: beginIndex -- the begin index, inclusive. endIndex -- the end inde

3.

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:

4. What will be the output of the following program code? class LogicalCompare{ public static void main(String args[]){ String str1 = new String("OKAY"); String str2 = new String(str1); System.out.println(str1 == str2); } }

Answer: Option

Explanation:

5.

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

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

Answer: Option D

Explanation:

7. 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:

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

Answer: Option C

Explanation:
equals() method of string class returns boolean value true if both the string are equal and false if they are unequal.

9.

The output of the following fraction of code is

public class Test{
        public static void main(String args[]){
	        String s1 = new String("Hello");
		String s2 = new String("Hellow");
		System.out.println(s1 = s2);
	}
}

Answer: Option B

Explanation:

10. 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()

11.

Determine output:

public class Test{
        public static void main(String args[]){ 	
		String s1 = "SITHA";
		String s2 = "RAMA";
		System.out.println(s1.charAt(0) > s2.charAt(0));
        }
}

Answer: Option A

Explanation:

Output will be True. Since when s1.charAt(0) ascii value is greater then s2.charAt(0). So it will return True.

12. 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:

13. toString() method is defined in

Answer: Option B

Explanation:

14. Which of these method of class String is used to obtain length of String object?

Answer: Option D

Explanation:
Method length() of string class is used to get the length of the object which invoked method length().

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

Answer: Option A

Explanation: