Convert HashSet to Enumeration in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

241 Views

Let’s say the following is our HashSet:HashSet set = new HashSet(); set.add("P"); set.add("Q"); set.add("R"); set.add("S"); set.add("T"); set.add("U"); set.add("V"); set.add("W"); set.add("X"); set.add("Z");Now convert the above HashSet to Enumeration:Enumeration enumeration = Collections.enumeration(set); while (enumeration.hasMoreElements())    System.out.println(enumeration.nextElement());Exampleimport java.util.Collections; import java.util.Enumeration; import java.util.HashSet; public class Demo {    public static void main(String[] args) {       HashSet set = new HashSet();       set.add("P");       set.add("Q");       set.add("R");       set.add("S");       set.add("T");       set.add("U");       set.add("V");       set.add("W");       set.add("X");       set.add("Z");   ... Read More

Search for a Date in MySQL Timestamp Field

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

817 Views

You can use DATE() function from MySQL for this. Let us first create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentAdmissionDate timestamp ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentAdmissionDate) values('2011-01-12 12:34:43'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(StudentAdmissionDate) values('2012-10-23 11:32:21'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(StudentAdmissionDate) values('2001-02-14 05:12:01'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentAdmissionDate) values('2018-12-31 15:10:04'); Query OK, 1 row affected (0.22 sec) mysql> ... Read More

FloatBuffer arrayOffset Method in Java

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

102 Views

The offset of the first element of the buffer inside the buffer array is obtained using the method arrayOffset() in the class java.nio.FloatBuffer. If the buffer backed by the array is read-only, then the ReadOnlyBufferException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          FloatBuffer buffer = FloatBuffer.allocate(5);          buffer.put(4.5F);          buffer.put(1.2F);          buffer.put(3.9F);         ... Read More

Use typeof in Android SQLite

Smita Kapse
Updated on 30-Jul-2019 22:30:25

230 Views

Before getting into an example, we should know what sqlite database in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built-in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrates How to use typeof () in Android sqliteStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a ... Read More

Read Form Data Using JSP via POST Method

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

3K+ Views

Below is the main.jsp JSP program to handle the input given by web browser using the GET or the POST methods.Infact there is no change in the above JSP because the only way of passing parameters is changed and no binary data is being passed to the JSP program. File handling related concepts will be explained in a separate chapter where we need to read the binary data stream.           Using GET and POST Method to Read Form Data                        Using POST Method to Read ... Read More

Get Current Activity Available Memory in Android

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

178 Views

This example demonstrates How to get current activity available memory in android.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 activity available memory.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.Context; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.TextView; public class MainActivity extends AppCompatActivity {   ... Read More

IntStream Map Method in Java

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

3K+ Views

The IntStream map() method returns the new stream consisting of the results of applying the given function to the elements of this stream.The syntax is as followsIntStream map(IntUnaryOperator mapper)Here, mapper parameter is a non-interfering, stateless function to apply to each elementCreate an IntStream and add some elementsIntStream intStream1 = IntStream.of(20, 35, 40, 55, 60);Now, map it with the new IntStream and display the updated stream elements applying the condition in the map() functionIntStream intStream2 = intStream1.map(a -> (a + a));The following is an example to implement IntStream map() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {   ... Read More

Duration plusMillis Method in Java

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

81 Views

An immutable copy of a duration where some milliseconds are added to it can be obtained using the plusMillis() method in the Duration class in Java. This method requires a single parameter i.e. the number of milliseconds to be added and it returns the duration with the added milliseconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofSeconds(1);       System.out.println("The duration is: " + d);       System.out.println("A copy with 1000 milliseconds added to the duration is: ... Read More

MongoDB getUsers and show Command Comparison

Smita Kapse
Updated on 30-Jul-2019 22:30:25

102 Views

Both the getUsers() method and SHOW command can be used to list all users in the Mongo shell.Case 1 − Using getUsers()The syntax is as follows −db.getUsers();Case 2 − Using show commandThe syntax is as follows −show users;Let us implement both the syntaxes in order to list all users in the Mongo shell.Case 1 − The first query is as follows −> db.getUsers();The following is the output −[    {       "_id" : "test.John",       "user" : "John",       "db" : "test",       "roles" : [          {   ... Read More

The accept Method in Java Stream Builder

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

1K+ Views

Add an element to the stream using the accept() method of Java Stream.Builder.The following is the syntax:void accept(T t)Here, t is the argument to be inserted.Import the following package for the Stream.Builder class in Java:import java.util.stream.Stream;First, declare a Stream.Builder:Stream.Builder builder = Stream.builder();Now, use the accept() method:builder.accept("Demo"); builder.accept("Text");The following is an example displaying how to implement accept() method of Stream.Builder in Java:Example Live Demoimport java.util.stream.Stream; public class Demo {    public static void main(String[] args){       Stream.Builder builder = Stream.builder();       builder.accept("Demo");       builder.accept("Text");       Stream str = builder.build();       str.forEach(System.out::println);   ... Read More

Advertisements