Found 7442 Articles for Java

Concatenation of Strings in Java

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

191 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

18K+ 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

910 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

717 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

663 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

168 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

5K+ 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

291 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.

How to remove the last character from a string in Java?

Alankritha Ammu
Updated on 26-Feb-2020 05:07:49

2K+ Views

The StringBuffer class contains a method known as deleteCharAt(). This method deletes the character at a specified index/position. You can use this method to delete/remove a particular character from a string in Java.Examplepublic class Test {    public static void main(String args[]){       String str = "hi welcome to Tutorialspoint";       StringBuffer sb= new StringBuffer(str);       sb.deleteCharAt(sb.length()-1);       System.out.println(sb);    } }Outputhi welcome to Tutorialspoint

Advertisements