Different Ways to Concatenate Strings in Java

Anjana
Updated on 26-Feb-2020 05:13:14

592 Views

You can concatenate two strings in Java either by using the concat() method or by using the ‘+’ , the “concatenation” operator.Examplepublic class ConncatSample {    public static void main(String []args) {       String s1 = "Hello";       String s2 = "world";       String res1 = s1.concat(s2);       String res2 = s1+s2;       System.out.print("Concatenation using method:: ");       System.out.println(res1);       System.out.print("Concatenation using operator:: ");       System.out.println(res2);    } }OutputConcatenation using method:: Helloworld Concatenation using operator:: Helloworld

Manipulating Strings in Java

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

709 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

Ways to Manipulate Strings in Java

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

188 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

Reverse a Given String While Preserving Space Position in Java

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

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

Remove 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

Fetch Single Result from a Table in Java MySQL

AmitDiwan
Updated on 26-Feb-2020 05:04:00

3K+ Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (1.37 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(101, 'Chris'); Query OK, 1 row affected (0.54 sec) mysql> insert into DemoTable values(102, 'David'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(103, 'Mike'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following output −+------+-------+ | Id   ... Read More

Insert Single Column into MySQL Table with Java

AmitDiwan
Updated on 26-Feb-2020 05:03:06

611 Views

Use INSERT INTO statement in the Java-MySQL connection code to insert a column.Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.54 sec)Here is the Java code to insert only a single column into a MySQL table.Exampleimport java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; public class InsertOneColumnDemo {    public static void main(String[] args) {       Connection con = null;       PreparedStatement ps = null;       try {          con = DriverManager.getConnection("jdbc:mysql://localhost:3306/web?" + "useSSL=false", "root", "123456");   ... Read More

Treat MySQL LONGTEXT as Integer in MySQL Query

AmitDiwan
Updated on 26-Feb-2020 05:02:08

336 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Value longtext    -> ); Query OK, 0 rows affected (0.94 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('778437437447488487476464644433334'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('9998888485775775757577578585'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('8888874757757757757757575675656'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('988757757574646'); Query OK, 1 row affected (0.09 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following ... Read More

Characteristics of a Module in Java 9

raja
Updated on 26-Feb-2020 05:01:28

370 Views

The module is a collection of code, data, and resources. It is a set of related packages and types like classes, abstract classes, and interfaces with code, data files, and some static resources.Below are some of the characteristics of a module.Characteristics of a module:A module must define an interface for communication with other modules.A module defines the separation between a module interface and module implementation.A module presents a set of properties that contains information.Two or more modules have nested together.A module has a clear, defined responsibility. Each function implemented by only one module.A module must able to tested independently from other modules.An error in a module can't propagate to other ... Read More

What Happens When Running SELECT WHERE ColumnName = 0 in MySQL

AmitDiwan
Updated on 25-Feb-2020 13:21:35

128 Views

The following syntax will fetch all the values from the column −select * from yourTableName where yourColumnName=0;Let us first create a table −mysql> create table DemoTable1791      (      FirstName varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1791 values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1791 values('John'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1791 values('Carol'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1791;This ... Read More

Advertisements