Anjana

Anjana

32 Articles Published

Articles by Anjana

Page 3 of 4

Different ways to concatenate Strings in Java

Anjana
Anjana
Updated on 26-Feb-2020 659 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

Read More

Write a C++ Program without Semicolons?

Anjana
Anjana
Updated on 11-Feb-2020 536 Views

There are multiple ways to write a C++ program without semicolons. Note that doing this is very bad practice and should never be used in real code. This is presented just as informational content. The easiest way to write a C++ Program without Semicolons is using if statements. Almost all statements in C++ can be treated as expressions. So, if we place the statement inside an if statement with a blank pair of parentheses, we don’t have to end it with a semicolon anymore. For example, Example#include int main() {    if (int N = 1) {       ...

Read More

How can I remove the leading and trailing spaces both at once from a string without using MySQL LTRIM() and RTRIM() functions?

Anjana
Anjana
Updated on 06-Feb-2020 173 Views

Other than LTRIM() and RTRIM() functions, MySQL has TRIM() function to remove leading and trailing function both at once from a string. The use of TRIM() function can be understood from the following example of a test_trim table which has a column ‘Name’ containing the names with leading and trailing spaces.Examplemysql> Select Name, TRIM(Name)AS 'Name Without Spaces' from test_trim; +---------------+---------------------+ | Name          | Name Without Spaces | +---------------+---------------------+ | Gaurav        | Gaurav              | | Rahul         | Rahul               | | Aarav         | Aarav               | +---------------+---------------------+ 3 rows in set (0.00 sec)

Read More

How can CONCAT() function be used with MySQL WHERE clause?

Anjana
Anjana
Updated on 30-Jan-2020 3K+ Views

Suppose from the table ‘Student’ we want to concatenate the values of columns, ‘Name’, ‘Address’ and ‘Columns’, based on the condition that is also a concatenation of values from columns, ’Name’, ‘Subject’, provided in WHERE clause with the help of CONCAT() function. We can use the following query to give the output −mysql> Select CONCAT(Name, ' ', 'Resident of', ' ', Address, ' ', 'is', ' ', 'Studying', ' ', Subject)AS 'Detail of Student' from Student WHERE CONCAT(Name, Subject) = "AaravHistory"; +----------------------------------------------+ | Detail of Student                            | ...

Read More

How can we use MySQL self-computed output from any expression, function etc. for inserting values in a row?

Anjana
Anjana
Updated on 29-Jan-2020 155 Views

While inserting the values in a row, we can use the value of self-computed output from any expression, function etc. Here is an example to demonstrate it −mysql> Insert into employee(id, emp_name)Select 1+1, Concat_ws(' ','Gaurav', 'Kumar'); Query OK, 1 row affected (0.04 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> Select * from employee; +------+--------------+ | id   | emp_name     | +------+--------------+ | 2    | Gaurav Kumar | +------+--------------+ 1 row in set (0.00 sec)

Read More

How can we use MySQL ALTER TABLE command for adding comments on columns?

Anjana
Anjana
Updated on 29-Jan-2020 2K+ Views

We can use ‘COMMENT’ keyword with ALTER TABLE command while modifying the column to add comments on columns. For example if we want to add comment in column ‘id’ of table ‘testing’ then following query will do it −mysql> ALTER TABLE testing MODIFY id INT COMMENT 'id of employees'; Query OK, 0 rows affected (0.07 sec) Records: 0 Duplicates: 0 Warnings: 0With following query it can be checked in the comment field of a column.mysql> Show full columns from testing\G *************************** 1. row ***************************      Field: id       Type: int(11)  Collation: NULL       Null: NO ...

Read More

How can we create our own choice MySQL database?

Anjana
Anjana
Updated on 28-Jan-2020 205 Views

CREATE DATABASE db_name can be used to create our own choice MySQL database. For example to create a database named Sample, we should have to run the command as follows −mysql> CREATE DATABASE Sample; Query OK, 1 row affected (0.04 sec)

Read More

Checking for Null or Empty or White Space Only String in Java.

Anjana
Anjana
Updated on 30-Jul-2019 2K+ Views

We can verify whether the given string is empty using the isEmpty() method of the String class. This method returns true only if length() is 0. Example import java.lang.*; public class StringDemo {     public static void main(String[] args) {         String str = "tutorialspoint";         // prints length of string         System.out.println("length of string = " + str.length());         // checks if the string is empty or not         System.out.println("is this string empty? = " + str.isEmpty());     } } Output length of string = 14 is this string empty? = false

Read More

Constructors of StringTokenizer class in Java.

Anjana
Anjana
Updated on 30-Jul-2019 312 Views

Following are the important constructors of the StringTokenizer class.Sr.No.Constructor & Description1StringTokenizer(String str)This constructor a string tokenizer for the specified string.2StringTokenizer(String str, String delim)This constructor constructs string tokenizer for the specified string.3StringTokenizer(String str, String delim, boolean returnDelims)This constructor constructs a string tokenizer for the specified string.

Read More

What is JAVA_HOME variable in Java Environment?

Anjana
Anjana
Updated on 30-Jul-2019 560 Views

JAVA_HOME refers to jdk/bin directory. It is used by a java based application.

Read More
Showing 21–30 of 32 articles
Advertisements