String functions in Java | #InternshalaTrainingsTalkies

preview_player
Показать описание
3 Bn+. That is the number of mobile phones running with Java and we aren't even counting computing systems, TV sets, or enterprise software. Developed in 1995, Java has been a popular programming language. Developers around the world learn Java because of 3 reasons: easy to learn (and to write, code, debug), is object-oriented (and reusable), and is platform-independent.

Java developers have been in demand from years and it doesn't slow down. #InternshalaTrainingsTalkies present a chance to learn a concept on-the-go and win an exciting prize.

In this tutorial, we will learn about strings in Java.

Comment to win a prize
Also, watch till the end and answer the question in the comments section. One lucky winner stands a chance to win an exciting Internshala Trainings merchandise.

How to learn Java and take the first step to become a Java developer?

Рекомендации по теме
Комментарии
Автор

Thanks for participating! The winner is Akash Kesharwani. All the best for the next one, guys :)

InternshalaOfficial
Автор

+ will add the string for display purpose only but concat() will actually add the following string to the existing string

artbreezes
Автор

+ operator is used join new object and concate function is used wether the join the two object
Concate is java String inbuilt method

sumitgharat
Автор

concat() method takes arguments of string type only. + operator takes any type of argument and converts it to string type and then combine them. concat() takes concatenates two strings and return new string object only string length is greater than 0, otherwise it returns same object

MunirajaPennella
Автор

+ operator only joins two strings(even if the address is specified) while the concat() method joins two strings to create a new string.

ananshagrawal
Автор

concat() method takes only string type parameter but + operater takes any type of the parameter.
concat () method takes to string object and return new string if and only if string length is greater then 0 other wise it will return the same string object.
concat () method raises null pointer exception if try to contact with null but +operater concrete with out raising and exception

sushmakurdekar
Автор

concate() is inbuilt method in java string, and + is operator is the join to object in java is can't inbuilt in string.
concate() is method .
And + is operators .
concate() method is use join two string object .
+ operators is use join both objects

sumitgharat
Автор

The original string isn't changed when using + operator, while the concat function makes changes to original string in memory.

+ operator allows multiple strings while concat function allows only one string argument at a time.

+ is an operator and will not have a luxury of exception. Where as concat has all the luxuries of a general java function.

jayantsharma_
Автор

1. Concat() accepts only string argument whereas + operator can take anything.
2.concat() can accept only one argument but + can take any number of arguments
3. Concat() will throw NullPointerException when assigned to null value but + will not.

aashrayasingal
Автор

In concat() method, takes only one argument of string type only and concatenate it with another string. While + operator takes any number of arguments and convert it to string type and then combines them.

sakshinegi
Автор

We have to use " " inverted coma while joining the string by + but we just have to write two strings which we want to add in concat() function

jaisharma
Автор

1. concat only two arguments. '+' takes any number of arguements
2. Concat only add string arguments. + first convert arguments to string then add
3. Concat raise Null point exception when string is added to null wheares + doesn't
4.concat make new object when the length of total string is greater than zero.
+ always make new objects irrespective of length of string
5. Concat use less memory so better in performance than +

piyushjha
Автор

concat() method takes only one argument of string and concat it with other string.
+ operator takes any number of arguments and concatenates all the strings.
strong>concat() method takes only string arguments, if there is any other type is given in arguments then it will raise an error.
+ operator takes any type and converts to string type and then concatenates the strings.
concat() method throws NullPointer Exception when string is concatenated with null.
+ operator did not raise any Exception when the string is concatenated with null.
concat() method takes concatenates two strings and return new string object only string length is greater than 0, otherwise it returns same object.
+ operator creates a new string object every time irrespective of length of string.
concat() method is better than + operator because it creates a new object only when the string length is greater than zero(0) but + operator always a creates a new string irrespective of length of string.

akashkesharwani
Автор


concat() method if called on null String reference variable, will throw NullPointerException; while this is not the case with + operator
Example     String str = null;  
str.concat(“abc”);  

While  
String str = null;  

output:- nullabc  
While concatenating strings with + operator, a null reference variable changes to “null” (i.e. a String containing null as its contents.). That’s why str becomes “null” and output is nullabc.
2.Number of arguments
concat() takes only one argument while + can take any number of arguments
Example
“Hello”+”James”+”Gosling”  
3.Type of Arguments
Concat() only takes String type as argument. If any other type of argument is passed to concat() it will give compile time error.
Example



While + can take any type of argument, while doing concatenation non-string type argument is converted to String by using its toString() method.

jyotipriyanshu
Автор

Concat method only accepts string as argument whereas in + operator we can use different datatype than a string as well

parbhatsharma
Автор

+ is the " " Colon visibility only the output
Concat() function is combining both

srikanthp
Автор

Basically three differences :

1) concat() throws NullPointerException when assigned to null value, but + operator doesn't.

2) + operator can have many arguments, but concat() can only have one argument passed to it.

3) concat() needs only string type argument if given any other then shows compilation error, but + operator doesn't.

dvnovov
Автор

A concat() method is a method to combine two strings . '+' operator is used to concatenate any number of strings. concat() method takes arguments of type "String" only. '+' operator takes any type of argument, converts it to type "String" and then combines them.

krishnasashank
Автор

+ operator is just showing the two strings together and they are still different..
But concat function is stiching them together and making them one

keshavsaini
Автор

There are mant differences, one among them is concat() method takes only one argument of string and concat it with other string whereas + operator takes any number of arguments and concatenates all the strings

tejaswik
welcome to shbcf.ru