- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4338 Articles for Java 8
![Akshaya Akki](https://www.tutorialspoint.com/assets/profiles/13526/profile/60_48621-1512703980.jpg)
108 Views
The concat() method of the String class concatenates the specified string to the end of this string.Exampleimport java.lang.*; public class StringDemo { public static void main(String[] args) { // print str1 String str1 = "self"; System.out.println(str1); // print str2 concatenated with str1 String str2 = str1.concat(" learning"); System.out.println(str2); // prints str3 concatenated with str2(and str1) String str3 = str2.concat(" center"); System.out.println(str3); } }Outputself self learning self learning center
![Sai Nath](https://www.tutorialspoint.com/assets/profiles/13525/profile/60_63072-1512539005.jpg)
180 Views
The equals() method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.ExampleLive Demopublic class Sample { public static void main(String []args) { String s1 = "tutorialspoint"; String s2 = "tutorialspoint"; String s3 = new String ("Tutorials Point"); System.out.println(s1.equals(s2)); System.out.println(s2.equals(s3)); } }Outputtrue falseYou can also compare two strings using == operator. But, it compares references to the given ... Read More
![Moumita](https://www.tutorialspoint.com/assets/profiles/13507/profile/60_122499-1557898491.jpg)
1K+ Views
You can create a String by -Assigning a string value wrapped in " " to a String type variable.String message = "Hello Welcome to Tutorialspoint";Creating an object of the String class using the new keyword by passing the string value as a parameter of its constructor.String message = new String ("Hello Welcome to Tutorialspoint");Passing a character array to the String constructor.char arr[] = {'H','e','l','l','o'}; String message = new String(arr);
![Manikanth Mani](https://www.tutorialspoint.com/assets/profiles/13524/profile/60_53242-1512705034.jpg)
136 Views
The Optimum Method to Concatenate Strings in Java is the concat() method.This method appends one String to the end of another. The method returns a String with the value of the String passed into the method, appended to the end of the String, used to invoke this method.ExampleLive Demopublic class Test { public static void main(String args[]) { String s = "Strings are immutable"; s = s.concat(" all the time"); System.out.println(s); } } OutputStrings are immutable all the time
![Ayyan](https://www.tutorialspoint.com/assets/profiles/13521/profile/60_79767-1512650417.jpg)
946 Views
If you try to concatenate strings using concat() method, you can concat variables of string data type only.To concatenate strings with other data type you need to use the ‘+’ operator.Examplepublic class Test { public static void main(String args[]){ String st1 = "Hello"; int data = 230; String res = st1+data; System.out.println(res); } }OutputHello230
![Anjana](https://www.tutorialspoint.com/assets/profiles/13774/profile/60_78029-1512648681.jpg)
4K+ Views
You can concatenate multiple strings using the ‘+’ operator of Java.Examplepublic class Test { public static void main(String args[]) { String st1 = "Hello"; String st2 = "How"; String st3 = "You"; String res = st1+st2+st3; System.out.println(res); } }OutputHelloHowYou
![Arushi](https://www.tutorialspoint.com/assets/profiles/13510/profile/60_55588-1512537391.jpg)
1K+ Views
Hashtable was part of the original java.util and is a concrete implementation of a Dictionary. However, Java 2 re-engineered Hashtable so that it also implements the Map interface. Thus, Hashtable is now integrated into the collections framework. It is similar to HashMap, but is synchronized.Like HashMap, Hashtable stores key/value pairs in a hash table. When using a Hashtable, you specify an object that is used as a key, and the value that you want to be linked to that key. The key is then hashed, and the resulting hash code is used as the index at which the value is ... Read More
![Akshaya Akki](https://www.tutorialspoint.com/assets/profiles/13526/profile/60_48621-1512703980.jpg)
208 Views
The notable differences between concat() method and +operator are:concat() method+operatorYou cannot concat a null value to a String using the concat() method.You can concat null value using the ‘+’ operator.Using the concat() method you can concat only two String variables.Using the ‘+’ operator you can concat multiple values.Using the concat() method you can concat only String type of arguments.Using the ‘+’ operator you can concat any type of arguments.
![Ayyan](https://www.tutorialspoint.com/assets/profiles/13521/profile/60_79767-1512650417.jpg)
527 Views
You can concatenate two strings in Java either by using the concat() method or by using the ‘+’ , the “concatenation” operator.The concat() methodThe concat() method appends one String to the end of another. This method returns a String with the value of the String passed into the method, appended to the end of the String, used to invoke this method.Examplepublic class ConncatSample { public static void main(String []args) { String s1 = "Hello"; String s2 = "world"; String res = s1.concat(s2); System.out.print("Concatenation result:: "); ... Read More
![Alankritha Ammu](https://www.tutorialspoint.com/assets/profiles/13523/profile/60_83090-1512649277.jpg)
109 Views
You can finish your task by combining/ concatenating your two stings using concat() method or + operator.Exampleimport java.util.Scanner; public class ConncatSample { public static void main(String []args) { Scanner sc = new Scanner(System.in); System.out.println("Enter your first name"); String firstName = sc.nextLine(); System.out.println("Enter your last name"); String lastName = sc.nextLine(); String completeName = firstName+lastName; System.out.print("Hi your complete name is :: "); System.out.println(completeName); } }OutputEnter your first name KrishnaKasyap Enter your last name BhagavatulaHi your complete ... Read More