ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Java Strings Aptitude Questions and Answers.
Page 2.

List of Java Strings Aptitude Questions

6) What will be the output of following program?
public class temp
{
	public static void main(String args[])
	{
		String text="ABCD";
		byte[] xByte=text.getBytes();
		
		for(byte loop: xByte)
		{
			System.out.print(loop+" ");
		}		
	}
}
  1. A B C D
  2. 41 42 43 44
  3. 65 66 67 68
  4. Error

7) What will be the output by following code snippet?
String text="Hello World, How are you?";
System.out.print(text.lastIndexOf('o'));
System.out.print(" "+text.lastIndexOf('o',5));
  1. 22 4
  2. 22 22
  3. 22 16
  4. None of these

8) What value will be printed after executing following code snippet?
String text="Hello World!";
int index= text.indexOf("llo");
System.out.println(index);
  1. 3
  2. 2
  3. -1
  4. Error

9) What value will be printed after executing following code snippet?
String text="Hello World!";
int index= text.indexOf("hello");
System.out.println(index);
  1. 1
  2. 0
  3. -1
  4. Error

10) What will be the output by following code snippet?
String Str = new String("   Include   Help  ");
System.out.println(Str.trim() );
  1.    Include   Help  
  2. Include   Help
  3.    Include   Help
  4. None of these





ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.