Java SE 8 Programmer I (1Z0–808) Important Questions 101 Day 2

Java SE 8 Programmer I (1Z0–808) Important Questions 101 Day 2

Question 2: The below question is based on StringBuilder and it is kind of important in general also.

just try to figure out what can be the possible output of the above code

OUTPUT

If you got the above answer you probably knows how it works so no need to read the article further but If not you can give it a try.

1. StringBuilder s1=new StringBuilder();

The above statement will create a char array internally with the default capacity of 16.

Below is the actual implementation of the code of the constructor

StringBuilder() {
value=new Char[16];
}

2. Now lets discuss what happens when we create a StringBuilder object when we pass a String

StringBuilder s2=new StringBuilder(“sandy”);

In this case the capacity will be initialCapacity + length of passed string = 21

3. So what happens when we pass an integer in StringBuilder construction

StringBuilder s3=new StringBuilder(10);

This will create a StringBuilder object with initial capacity as 10.

This is it and now you can go and read more article on it.

Learning, Unlearning and Repeating.

Hi Everyone I am a Software Developer in one of the big tech companies. While I am preparing for the OCA 1Z0–808 this certification is for the java 8 and for the associate level after that we have one for the professional level. Coming back to the thing why I am writing this series of blog posts because these are some of the most important questions and difficult topics that I have faced while I was preparing for the exam. It will be easier for you to just read the full explanation for the questions and understanding the topics. :)