The first and last elements of a Linked List can be obtained using the methods java.util.LinkedList.getFirst() and java.util.LinkedList.getLast() respectively. Neither of these methods require any parameters.A program that demonstrates this is given as followsExample Live Demoimport java.util.LinkedList; public class Demo { public static void main(String[] args) { LinkedList l = new LinkedList(); l.add("John"); l.add("Sara"); l.add("Susan"); l.add("Betty"); l.add("Nathan"); ... Read More
Before getting into card view for recycler view example, we should know what is Recycler view in android. Recycler view is more advanced version of list view and it works based on View holder design pattern. Using recycler view we can show grids and list of items.card view is extended by frame layout and it is used to show the items in card manner. It supports radius and shadow as predefined tags.This example demonstrate about how to integrate Recycler View with card view by creating a beautiful student records app that displays student name with age.Step 1 − Create a ... Read More
You can quote values using concat() and grop_concat() function from MySQL. The syntax is as follows −SELECT GROUP_CONCAT(CONCAT(' '' ', yourColumnName, ' '' ' )) as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table Group_ConcatDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Value int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (1.56 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into Group_ConcatDemo(Value) ... Read More
Born in 1812 in London, Robert Browning enjoys the pinnacle of popularity only because of his prowess to portray his thoughts. You can understand it with this fact that his grave is now adjacent to that of Lord Alfred Tennyson.His Famous Works"Pauline, a Fragment of a Confession" , which is a long poem composed in homage to P.B. Shelley, “My Last Duchess”, “Porphyria’s lover”, “Andrea del Sarto”, “ A grammarian’s funeral”, Men and Women are some of his popular works for which he is remembered even now.Browning’s Unique Writing StyleDramatic Monologue: His critical reputation rests mainly due to his dramatic ... Read More
The statement now()+1 day itself states that we need to add a day to the current datetime. You can write the above logic like this −now()+interval 1 day;Or you can write same logic with date_add() function from MySQL like this −date_add(now(), interval 1 day);Let us use the above concept with MySQL select statement. The query is as follows −mysql> select now()+ interval 1 day;Here is the sample output that increments a day by 1 −+-----------------------+ | now()+ interval 1 day | +-----------------------+ | 2018-11-23 15:43:10 | +-----------------------+ 1 row in set (0.05 sec)Now, let us see another example ... Read More
The “M” format is to format months i.e. 1, 2, 3, 4, etc. Here, we will use the following.SimpleDateFormat("M");Let us see an example −// displaying month with M format simpleformat = new SimpleDateFormat("M"); String strMonth = simpleformat.format(new Date()); System.out.println("Month in M format = "+strMonth);Above, we have used the SimpleDateFormat class, therefore the following package is imported −import java.text.SimpleDateFormat;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time ... Read More
Let us create a table to sort date and time in ascending order. The query to create a table is as follows −mysql> create table SortByDateAndTime -> ( -> UserId int, -> UserName varchar(100), -> IssueDate date, -> IssueTime time -> ); Query OK, 0 rows affected (0.60 sec)Insert the records in the table using insert command. The query is as follows −mysql> insert into SortByDateAndTime values(1, 'John', '2018-12-16', '10:30'); Query OK, 1 row affected (0.14 sec) mysql> insert into SortByDateAndTime values(2, 'Bob', '2018-12-16', '10:10'); Query OK, 1 row affected (0.14 sec) ... Read More
To re-order columns in MySQL, use the ALTER TABLE MODIFY COLUMN. The syntax is as follows -ALTER TABLE yourTableName MODIFY COLUMN yourColumnName data type after yourColumnName.To understand the above syntax, let us first create a table. The query to create a table is as follows.mysql> create table reOrderColumn -> ( -> ProductId int, -> DeliveryDate datetime, -> ProductName varchar(100) -> ); Query OK, 0 rows affected (0.76 sec)Now check the description of the table. The query is as follows.mysql> desc reOrderColumn;The following is the output.+--------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------+-------+ | ... Read More
You can achieve this with the help of INSERT INTO SELECT statement. The syntax is as follows −INSERT INTO yourDatabaseName.yourTableName(SELECT *FROM yourDatabaseName.yourTableName);To understand the above syntax, let us create a table in a database and second table in another databaseThe database name is “bothinnodbandmyisam”. Let us create a table in the same database. The query is as follows −mysql> create table Student_Information -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(10), -> Age int -> ); Query OK, 0 rows affected (0.67 sec)Now you can insert some records in the ... Read More
To list non-empty tables in MySQL database, use “information_schema.tables”. The following is the query for all database tables −mysql> select table_type, table_name from information_schema.tables −> where table_rows >= 1;Above, we have considered only the table that have 1 or more than 1 rows i.e. non-empty table.The following is the output −+------------+------------------------------------------------------+ | TABLE_TYPE | TABLE_NAME | +------------+------------------------------------------------------+ | BASE TABLE | innodb_table_stats ... Read More