Found 9326 Articles for Object Oriented Programming

The Optimum Method to Concatenate Strings in Java.

Manikanth Mani
Updated on 26-Feb-2020 06:02:08

135 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

Java String Concatenation with Other Data Types.

Ayyan
Updated on 26-Feb-2020 05:44:11

921 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

Concatenate Multiple Strings in Java.

Anjana
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

Arushi
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

Akshaya Akki
Updated on 30-Jul-2019 22:30:21

200 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

Ayyan
Updated on 26-Feb-2020 05:16:46

526 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

Alankritha Ammu
Updated on 26-Feb-2020 05:14:28

108 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?

Fendadis John
Updated on 26-Feb-2020 05:48:03

15K+ 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?

Sai Nath
Updated on 30-Jul-2019 22:30:21

741 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?

Anjana
Updated on 30-Jul-2019 22:30:21

510 Views

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

Advertisements