STRING CONCATENATION:
appending a string to another string is known as string concatenation.
the '+' icon functions as the concatenation owner.
NOTE:-
+ owner performs as an mathematics owner if and only if the two operands provided to the + owner are mathematics number
+ owner performs as a concatenation owner if at least one operand provided to the + owner is a Sequence object
concatenation owner always results a new string category item with the material of LHS and RHS of the + owner.
EX:
Program.out.println (s1); // it printing abcxyz.
Sequence s2="msd"; Program.out,println(s2); // MSD is printed
S2=s2 + "SA"; Program.out.println (s2); // MS D S S A is printed
We said that Sequence are immutable (i.e material of the item of Sequence category cannot be changed) but how are the above claims possible?
Actually the material of the item by S2 id not personalized. Actually a new item is designed and some new the whole material is appended to the current material and this is saved is in the item and deal with of the item is allocated to the varying. That's all in the above example the material "MSD" is not at all customized some new material "SSA" is included to it and then the whole material is saved in a new item.
Using concatenation owner we can signify all the basic information kinds by means of their comparative Sequence category things.
int x=10;
Sequence s4="";
s4=s4+10;
Program.ut.println(s4); // 10 is printed
int x =10;
Sequence s3="MSD"+10
Program.out.println(s3); // MSD 10is printed
Sequence s5 = "xyz"+x+10;
Program.out.println(s5); // xyz1010 is printed
Sequence s6=x+10+ "abc";
Program.out.println (s6) ; // 20abc is printed
string s7 = "abc" +x+3;
*operator has more concern (procedure) over + operator
Program.out.printeln (s7); // abc 30 is printed
Sequence s7 = x* "abc" +3; // It gives error
because * owner performs only on mathematics numbers
STRING BUFFER CLASS:
We said that Sequence are immutable. But we have another category by name String Buffer category the materials of whose things are mutable i.e we can change the material of the item which is designed upon the String Buffer class
EX:
StringBuffer SBI=new StringBuffer ("abc");
Some of the technique available in the string barrier category are add (); eliminate (); substitute (); e.t.c by using these techniques we can change the material of the item of Pattern barrier category.
StringBuffer sb2 = new Sequence ("xyz");
Sequence s3 = new StringBuffer ("abc"); // gives a collection error
Both the above claims are not valid claims : the purpose us we are trying to determine item of one category to testimonials of another category which is against the concept that an item of a category should be allocated to the referrals varying of the kind same category.
No comments:
Post a Comment