Create String Object in Java

Moumita
Updated on 26-Feb-2020 05:55:48

2K+ Views

You can create a String by -Assigning a string value wrapped in " " to a String type variable.String message = "Hello Welcome to Tutorialspoint";Creating an object of the String class using the new keyword by passing the string value as a parameter of its constructor.String message = new String ("Hello Welcome to Tutorialspoint");Passing a character array to the String constructor.char arr[] = {'H','e','l','l','o'}; String message = new String(arr);

Order VARCHAR Records with Strings and Numbers in MySQL

AmitDiwan
Updated on 26-Feb-2020 05:52:01

540 Views

For this, use ORDER BY clause. Let us first create a table −mysql> create table DemoTable    -> (    -> StudentCode varchar(20)    -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('101J'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('100A'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('100B'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('101S'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('103M'); Query OK, 1 row affected (0.15 ... Read More

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

String Handling in Java

Arushi
Updated on 26-Feb-2020 05:46:34

17K+ Views

Strings, which are widely used in Java programming, are a sequence of characters. In Java programming language, strings are treated as objects.The Java platform provides the String class to create and manipulate strings.The most direct way to create a string is to write −String greeting = "Hello world!";Whenever it encounters a string literal in your code, the compiler creates a String object with its value in this case, "Hello world!'.ExampleLive Demopublic class StringDemo {    public static void main(String args[]) {       char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.' };       String helloString ... Read More

Get Number of Users of Different Type in MySQL

AmitDiwan
Updated on 26-Feb-2020 05:46:26

329 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> UserName varchar(20),    -> UserType ENUM('New User', 'Registered User')    -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'New User'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David', 'New User'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('Mike', 'Registered User'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Sam', 'New User'); Query OK, 1 row affected (0.10 sec)Display all records ... Read More

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

Round Records with Numbers in MySQL

AmitDiwan
Updated on 26-Feb-2020 05:41:20

215 Views

To round number, use MySQL ROUND(). Let us first create a table −mysql> create table DemoTable    -> (    -> Amount DECIMAL(10, 4)    -> ); Query OK, 0 rows affected (1.18 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100.578); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(1000.458); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(980.89); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following output−+-----------+ | Amount    | ... Read More

Display Record with Most Recent Time in MySQL

AmitDiwan
Updated on 26-Feb-2020 05:40:31

197 Views

You can use ORDER BY STR_TO_DATE(). Let us first create a table −mysql> create table DemoTable    -> (    -> DueTime varchar(20)    -> ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('7:30AM'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('9:00PM'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('11:00PM'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following output−+---------+ | DueTime | +---------+ | ... Read More

MySQL Syntax Error in SELECT Query Using GROUP as Table Name

AmitDiwan
Updated on 26-Feb-2020 05:39:11

1K+ Views

The group is a reserved keyword, you can’t use it as table name. Therefore, on using it as table name would lead to an error. To avoid such error, you need to use enclosed backticks symbol around the table name ‘group’.Let us now see an example and create a table −mysql> create table `group`    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (1.26 sec)Insert some records in the table using insert command −mysql> insert into `group`(Name) values('Chris'); Query OK, 1 row affected (0.47 sec) ... Read More

Set Conditions While Adding Column Values in MySQL

AmitDiwan
Updated on 26-Feb-2020 05:38:16

337 Views

To set conditions while adding column values, use MySQL IF(). Let us first create a table −mysql> create table DemoTable    -> (    -> Value1 int,    -> Value2 int,    -> Value3 int    -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 20, -30); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(50, 60, 90); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(100, 200, 400); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(30, ... Read More

Advertisements