In this article, we will learn to sort ArrayList of custom objects by property in Java. The ArrayList class extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as needed. Problem Statement ArrayList is created with an initial size. When this size is exceeded, the collection is automatically enlarged. When objects are removed, the array may be shrunk. Below is a demonstration of the same − Input − The list is defined as Java Scala Python Mysql Output − The list after sorting values: Java Mysql Python Scala ... Read More
In this article, we will learn to convert milliseconds to readable strings in Java. Converting milliseconds into a human-readable format such as hours, minutes, seconds, and milliseconds is a common programming task, especially in time-sensitive applications. Problem Statement The challenge is to convert a given time in milliseconds into a readable string that shows hours, minutes, seconds, and remaining milliseconds. Input long millis = 5000000; Output Hours = 1 Minutes = 23 Seconds = 20Milliseconds = 0 1 hr(s) 23 min(s) 20 sec(s) 0 ms Approaches to convert millisecond to readable string Following are the two different approaches to converting milliseconds ... Read More
In MySQL, the ENUM is a data type that is used to create a column with a fixed set of values. It is helpful for the fields that have limited alternatives, such as categories, statuses, and color codes. In the ENUM data type, if you do not declare NOT NULL then it gives the default value NULL or Empty String('') when inserting records without specifying a value. However, if you declare NOT NULL and don't specify the values when inserting then it gives the first value from the ENUM. Following is the syntax to create a table that has ... Read More
Yes, you can include a string value with spaces in ENUM type. This is particularly useful when we add descriptive options that contain multiple words. Let us explore how to create, describe, and use ENUM columns containing spaces, with supporting examples. ENUM vs VARCHAR: While both ENUM and VARCHAR can store strings with spaces, ENUM has an advantage: limiting of the number of entries that can be added into a column to a fixed set. Because of this, it is useful in situations where the values are limited and static, such as size categories, and status codes. Whereas VARCHAR is ... Read More
No, SQL Server doesn’t offer a direct equivalent to MySQL’s ENUM data type, but you can replicate similar functionality with a combination of VARCHAR, and a CHECK constraint. This allows you to restrict the possible values for a column, just like ENUM does in MySQL. This article will look at how SQL Server can handle ENUM-like behavior and examples of how it is being utilized in your database design. Enum in MySQL In MySQL, the ENUM is a data type that is used to create a column with a fixed set of predefined values which allows data integrity. ... Read More
Removing Value from an enum in MySQL We can use the ALTER command to remove a value from an ENUM in MySQL. The ALTER database command lets you modify the type of a column, add or remove columns, or even modify ENUM values in a current database. You cannot delete a value from an ENUM type. To accomplish that task, you change the column definition - by changing the list of allowed values. This way, the structure of the table is not changed while the set of possible values for the ENUM column is changed. Example Let us first create ... Read More
When designing a database, setting default values for certain fields will improve data integrity. In MySQL, ENUM data type allows you to specify predefined values for a column such as status (complete or incomplete). This article helps you to set a default value for ENUM columns, to ensure that even if the data is missing, a suitable value is automatically assigned. Inserting a default value with ENUM data type We can do this with the help of the DEFAULT attribute of the ENUM data type. The DEFAULT attribute causes an ENUM data type to have a default value when a ... Read More
Stored Procedures Stored Procedures is a group of pre-compiled SQL statements that is stored in a database and can be reused anytime. It allows you to do many things in one command. So doing several activities in a database will be easier and quicker than before. A stored procedure can be called from SQL commands as well as applications like Python, Java, or PHP. Syntax Following is the syntax to create a stored procedure − CREATE PROCEDURE procedure_name AS BEGIN -- SQL statements END; Example Let us create a stored procedure where it ... Read More
Counting ENUM items in MySQL In MySQL, ENUM is a data type where it stores the predefined and fixed values making them ideal for categories such as sizes, grades, and statuses. Knowing the frequency of each value inside ENUM columns will allow you to make data-driven decisions. Below, we'll learn how to use MySQL's GROUP BY and COUNT() functions to get the count of ENUM values. GROUP BY(): It is used for aggregating data, as it follows you to perform calculations, such as totals, and averages. ... Read More
In MySQL, a trigger is a group of SQL statements performed or fired when a specified event is taken place on tables. The events can include INSERT, UPDATE, and DELETE. Such triggers are used for automating repetitive work, ensuring integrity in data, and keeping audit records without human involvement. The FOLLOWS keyword in MySQL allows the creation of several triggers for the same event and also allows you to select the order of execution. Creating Multiple Triggers for the Same Event When working with triggers, sometimes you might need to define several triggers for the same ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP