Discussion
What will be the output of the program?
public class Sample13
{
Sample13()
{
StringBuilder path = new StringBuilder("/usr/local/bin");
path.delete(4, 10);
System.out.println(path);
}
public static void main(String[] args)
{
new Sample13();
}
}
Answer: A
delete removes from the start index inclusive to the end index exclusive, so positions 4 through 9 go and position 10 stays. That takes out /local and leaves /usr/bin. The half-open range is the same convention substring uses, and forgetting it removes one character too many or too few.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development