Found 34489 Articles for Programming

Concatenate Multiple Strings in Java.

Naveen Singh
Updated on 26-Feb-2020 05:43:30

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

Differences between HashMap and Hashtable in Java

Naveen Singh
Updated on 18-Jun-2020 07:12:18

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

Java string concat() method vs "+" operator

Naveen Singh
Updated on 30-Jul-2019 22:30:21

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.

String Concatenation in Java

Naveen Singh
Updated on 26-Feb-2020 05:16:46

531 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

Concatenation of Strings in Java

Naveen Singh
Updated on 26-Feb-2020 05:14:28

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

How to import java.lang.String class in Java?

Naveen Singh
Updated on 26-Feb-2020 05:48:03

16K+ Views

To import any package in the current class you need to use the import keyword asimport packagename;ExampleLive Demoimport java.lang.String; public class Sample {    public static void main(String args[]) {       String s = new String("Hello");       System.out.println(s);    } }OutputHello

Why we do not import a package while we use any string function?

Naveen Singh
Updated on 30-Jul-2019 22:30:21

747 Views

The String class belongs to the java.lang package. This is the default package of the Java language therefore it is not mandatory to import it to use its classes.

Is StringBuffer final in Java?

Naveen Singh
Updated on 30-Jul-2019 22:30:21

524 Views

Yes, StringBuffer class is final Java. We cannot override this class.

What is the package for String Class in Java?

Naveen Singh
Updated on 30-Jul-2019 22:30:21

4K+ Views

String class belongs to the java.lang package.

Manipulating Strings in Java.

Naveen Singh
Updated on 26-Feb-2020 05:12:20

531 Views

Since String class is immutable once created we cannot modify the data of the string. But still if you want to manipulate string data you can rely on StringBuffer or StringBuilder classes.Examplepublic class Test {    public static void main(String args[]) {       String str = "Hi welcome ";       StringBuffer sb= new StringBuffer(str);       sb.append("to Tutorialspoint");       System.out.println(sb);    } }OutputHi welcome to Tutorialspoint

Advertisements