Found 9321 Articles for Object Oriented Programming

String Concatenation in Java

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

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

Concatenation of Strings in Java

Alankritha Ammu
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?

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

743 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

517 Views

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

What is the package for String Class in Java?

Jai Janardhan
Updated on 30-Jul-2019 22:30:21

4K+ Views

String class belongs to the java.lang package.

Manipulating Strings in Java.

Manikanth Mani
Updated on 26-Feb-2020 05:12:20

530 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

Are there any ways to Manipulate Strings in Java.

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

98 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

Java Program to reverse a given String with preserving the position of space.

Akshaya Akki
Updated on 26-Feb-2020 05:09:40

3K+ Views

You can reverse the contents of a given String using leaving the spaces using the reverse() method of the StringBuffer class.Examplepublic class Test {    public static void main(String args[]) {       String str = "hi welcome to Tutorialspoint";       String strArray[] = str.split(" ");       StringBuffer sb= new StringBuffer(str);       sb.reverse();       for(int i=0 ; i

Learn Everything about Java String?

George John
Updated on 30-Jul-2019 22:30:21

129 Views

The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings are constant, their values cannot be changed after they are created. To learn more about Strings visit Tutorialspoint Strings page.

Advertisements