The default capacity of a StringBuffer object in Java is 16 characters, not 16 bytes. Each character in a StringBuffer is typically represented using 2 bytes (16 bits) in UTF-16 encoding. Therefore, a StringBuffer with a capacity of 16 characters can hold up to 32 bytes of data. If you need to store more characters in a StringBuffer, it will automatically increase its capacity.
any new string you create for str. gives me error Multiple markers at this line - str cannot be resolved to a variable - Syntax error on token ":", invalid AssignmentOperator
What if we use append for String as same as like StringBuffer Now String can be mutable right? We can append to String also using append() So how to verify that now ?
The String class does not provide an append() method. Instead, if you need to manipulate or build strings dynamically, you should use StringBuffer or StringBuilder, which are mutable.
Stringbuilder is fast but not threadsafe.... StringBuffer is slow but threadsafe..... It depends upon the use case..... So, yeah StringBuilder is not obsolete... It's the same with vector(slow but threadsafe)and arraylist ( fast but not threadsafe)
java.lang.StringBuffer You dont need to import any bibilotecas first because the methods shown in the video are already predefined in the standard java library class.
Hello Sir, public class Test { public static void main(String[] args) { StringBuffer sb = new StringBuffer("Hello"); sb.append(" World"); System.out.println(sb); System.out.println(sb.capacity()); } } Why I'm getting the capacity as 21 instead of 27?
In the StringBuffer class, when appending to a string, the capacity will not change unless the length of the appended string exceeds the difference between the current capacity and the length of the string.
the whole point of this video should've been explaining why and when to use StringBuffer and how it is thread safe - with an example.
Imagine Navin sir conducting interview and the interviewe answering everything by watching his videos😅 sir be like Bro your are in😝
Yeah😂
The default capacity of a StringBuffer object in Java is 16 characters, not 16 bytes. Each character in a StringBuffer is typically represented using 2 bytes (16 bits) in UTF-16 encoding. Therefore, a StringBuffer with a capacity of 16 characters can hold up to 32 bytes of data.
If you need to store more characters in a StringBuffer, it will automatically increase its capacity.
Thank You so much Navin sir for this awesome lecture!!!
Doubt: Why is the capacity of the String Buffer not extending after we appending a new string or char to the existing string buffer???
You are the best Navin
i love to do like add delete insert and index no nut i think u need to explain some more like this
Sir at beginning u told stringbuffer will have capacity 16, what if we assign a string length greater than 16??
it will add 16 which is inital capacity + "your string is greater than 16"... so now the capacity will be 16 + your string length.
@@sandeepkumarbrungi7574 Thank you bro!
if ur String is "TELUKOO" which is of size 7, so now it will add 7+16=23
Thank you so Much Sir
any new string you create for str. gives me error
Multiple markers at this line
- str cannot be resolved to a variable
- Syntax error on token ":", invalid
AssignmentOperator
What if we use append for String as same as like StringBuffer
Now String can be mutable right?
We can append to String also using append()
So how to verify that now ?
The String class does not provide an append() method. Instead, if you need to manipulate or build strings dynamically, you should use StringBuffer or StringBuilder, which are mutable.
when i type (str: "navin"); it says str cannot be resolved to a varriable
Type just ("Navin"), without 'str:'
Is string builder obsolete because string buffer is same as string builder and also threadsafe?
Stringbuilder is fast but not threadsafe....
StringBuffer is slow but threadsafe.....
It depends upon the use case.....
So, yeah StringBuilder is not obsolete...
It's the same with vector(slow but threadsafe)and arraylist ( fast but not threadsafe)
public class Main{
public static void main(String[] args) {
String word = "Hello";
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(word);
stringBuffer.insert(0, "Howdy ");
stringBuffer.append(" Hi");
System.out.println(stringBuffer.toString());
System.out.println(stringBuffer.capacity());
System.out.println(stringBuffer.length());
System.out.println();//Division
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(word);
stringBuilder.insert(0, "Howdy ");
stringBuilder.append(" Hi");
System.out.println(stringBuilder.toString());
System.out.println(stringBuilder.capacity());
System.out.println(stringBuilder.length());
}
}
Hellosir if I doing your join chanel then you get me extra benifit
Sir is this playlist enough to learn java completey?
yes mam
what do bibliotecas i need to import first
java.lang.StringBuffer
You dont need to import any bibilotecas first because the methods shown in the video are already predefined in the standard java library class.
amazing
Why are you not updating VS Code? Please update VS Code.
Hello Sir,
public class Test {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("Hello");
sb.append(" World");
System.out.println(sb);
System.out.println(sb.capacity());
}
}
Why I'm getting the capacity as 21 instead of 27?
Have you tried by keeping the "Hello World" in StringBuffer Constructor?
In the StringBuffer class, when appending to a string, the capacity will not change unless the length of the appended string exceeds the difference between the current capacity and the length of the string.
Bro you are a telugu guy
bro you're still learning while making the video tf
Why would anyone in right mind use VS code for java
its simply superior
What is niqqa mumbling?
JAVA REDDY 😂