Fill Multiple Copies of Specified Object to a List in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

831 Views

To fill multiple copies of specified object to a list means let’s say you have an element 100 and want to display it 10 times. For this, let us see an example.The following is our list and iterator. We have used nCopiec Collections method to set the elements and how many copies you want −Listlist = Collections.nCopies(10, 100); Iteratoriterator = list.iterator();After that display the multiple copies −while (iterator.hasNext()) System.out.println(iterator.next());Example Live Demoimport java.util.Collections; import java.util.Iterator; import java.util.List; public class Demo {    public static void main(String[] args) {       Listlist = Collections.nCopies(10, 100);       Iteratoriterator = list.iterator();   ... Read More

Add Leading Zeros to Numbers with Less Than 9 Digits in MySQL

Chandu yadav
Updated on 30-Jul-2019 22:30:25

334 Views

Use LPAD() to add 0's to numbers with less than 9 digits. Let us first create a table −mysql> create table DemoTable (    Value varchar(20) ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('3646465'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('9485757591'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('485756'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('959585'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('124'); Query OK, 1 row affected ... Read More

SecureRandom generateSeed Method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

192 Views

The number of seed bytes can be obtained using the method generateSeed() in class java.security.SecureRandom. This method requires a single parameter i.e. the number of seed bytes and it returns the seed bytes that are generated.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");          byte[] arrB = sRandom.generateSeed(5);          System.out.println("The seed bytes generated are: " + Arrays.toString(arrB));       } catch (NoSuchAlgorithmException e) ... Read More

MySQL DATETIME: Now Plus 5 Days, Hours, Minutes, Seconds

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

565 Views

To update the current date and time to 5 days, you need to use the Now() + 5. That would update the entire date-time i.e. days, hour, minutes and seconds. To understand this, let us create a table. The query to create a table is as follows −mysql> create table UserInformationExpire    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserName varchar(10),    -> UserInformationExpireDateTime datetime not null    -> ); Query OK, 0 rows affected (0.83 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> ... Read More

Get Android Device Broad Name Programmatically

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

297 Views

This example demonstrates How to get programmatically android device broad name.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. In the above code, we have taken text view to show device board name.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.Manifest; import android.app.ProgressDialog; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.webkit.CookieManager; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; ... Read More

JDBC Program Demonstrating Batch Processing with CallableStatement

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

888 Views

Grouping related SQL statements into a batch and executing/submitting them at once is known as batch processing. The Statement interface provides methods to perform batch processing such as addBatch(), executeBatch(), clearBatch().Follow the steps given below to perform batch updates using the CallableStatement object:Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as a parameter.Connect to the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Set the auto-commit to false using setAutoCommit() method of the Connection interface.Create a CallableStatement object ... Read More

LocalTime hashCode Method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

147 Views

The hash code value of the LocalTime can be obtained using the hashCode() method in the LocalTime class in Java. This method requires no parameters and it returns the hash code value of the LocalTime.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo { public static void main(String[] args) {    LocalTime lt = LocalTime.parse("23:15:30");       System.out.println("The LocalTime is: " + lt);       System.out.println("The hash code is: " + lt.hashCode());    } }outputThe LocalTime is: 23:15:30 The hash code is: -387418074Now let us understand the above program.First the LocalTime is displayed. ... Read More

IntStream.range Method in Java

Anvi Jain
Updated on 30-Jul-2019 22:30:25

10K+ Views

The range() method in the IntStream class in Java is used to return a sequential ordered IntStream from startInclusive to endExclusive by an incremental step of 1. This includes the startInclusive as well.The syntax is as follows −static IntStream range(int startInclusive, int endExclusive)Here, the parameter startInclusive includes the starting value, whereas endExclusive excludes the last valueTo work with the IntStream class in Java, import the following package −import java.util.stream.IntStream;Create an IntStream and add stream elements in a range using range() method. This returns a sequential ordered IntStream by an incremental step of 1 within the range −intStream.forEach(System.out::println);The following is an ... Read More

Get All MySQL Records from the Previous Day

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

2K+ Views

To get the records from the previous day, the following is the syntaxselect *from yourTableName where date(yourColumnName)= DATE(NOW() - INTERVAL 1 DAY);To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table yesterDayRecordsDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ArrivalDateTime datetime    -> ); Query OK, 0 rows affected (0.44 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into yesterDayRecordsDemo(ArrivalDateTime) values('2014-11-09 13:45:21'); Query OK, 1 row affected (0.11 sec) mysql> insert into yesterDayRecordsDemo(ArrivalDateTime) values('2017-10-19 11:41:31'); Query ... Read More

MySQL Index on Column of INT Type

Chandu yadav
Updated on 30-Jul-2019 22:30:25

606 Views

Adding an index on column of int type is a good choice to run your query faster whenever your table has lots of records.If your table has less records then it is not a good choice to use index on column of int type.To understand the concept, let us create a table. The query to create a table is as follows −mysql> create table indexOnIntColumnDemo    -> (    -> UserId int,    -> UserName varchar(20),    -> UserAge int,    -> INDEX(UserId)    -> ); Query OK, 0 rows affected (0.85 sec)Now check the description of table −mysql> desc ... Read More

Advertisements