Use Length in Android TextView

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

963 Views

This example demonstrate about How to use length () in Android textview.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 the name as Edit text, when user click on button it will take data and check length of entered value is 0 or more than zero than returns last index of “sai”.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; ... Read More

IntStream forEach Method in Java

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

493 Views

The forEach() method is used in Java to perform an action for each element of this stream. Display the stream using the forEach() method in Java IntStreamThe syntax is as followsvoid forEach(IntConsumer action)Here, action is a non-interfering action to perform on the elements.Create IntStream and add elementsIntStream intStream = IntStream.of(15, 30, 40, 60, 75, 90);Now, display the streamintStream.forEach(System.out::println);The following is an example to implement IntStream forEach() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream = IntStream.of(15, 30, 40, 60, 75, 90);       intStream.forEach(System.out::println); ... Read More

Ennead Class in JavaTuples

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

124 Views

An Ennead class is a Tuple of 9 elements. It is in the JavaTuples library. The following is the declaration of the Ennead classpublic final class Ennead extends Tuple implements IValue0, IValue1, IValue2, IValue3, IValue4, IValue5, IValue6, IValue7, IValue8Let us first see what we need to work with JavaTuples. To work with Ennead class in JavaTuples, you need to import the following packageimport org.javatuples.Ennead;Note − Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples jar file. ... Read More

MongoDB Query with OR Condition

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

480 Views

To understand the query with an or condition, let us create a collection with the document. The query to create a collection with a document is as follows −> db.orConditionDemo.insertOne({"CustomerName":"Larry", "ShippingDate":new ISODate("2018-01-29")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ec5262f684a30fbdfd56a") } > db.orConditionDemo.insertOne({"CustomerName":"Mike", "ShippingDate":new ISODate("2019-04-13")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ec5362f684a30fbdfd56b") } > db.orConditionDemo.insertOne({"CustomerName":"Bob", "ShippingDate":new ISODate("2019-02-21")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ec5422f684a30fbdfd56c") } > db.orConditionDemo.insertOne({"CustomerName":"David", "ShippingDate":new ISODate("2019-03-15")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ec5532f684a30fbdfd56d") } > db.orConditionDemo.insertOne({"CustomerName":"John", "ShippingDate":new ISODate("2019-03-19")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ec56c2f684a30fbdfd56e") }Display all documents ... Read More

Convert Date Object to Timestamp in JDBC Program

Nitya Raut
Updated on 30-Jul-2019 22:30:25

727 Views

The getTime() method of the java.sql.Date class retrieves and returns the time from the current timestamp in milliseconds (long) from epoch time 1, 1970 00:00:00.000 GMT.//Retrieving the date Date date = rs.getDate("Dispatch_Date");The constructor of the java.sql.Timestamp class accepts a long variable representing the time in milliseconds from the epoch time and constructs the Timestamp object.//Creating a Timestamp object. Timestamp ts = new Timestamp(date.getTime()));Using these, you can convert a Date object to TimeStamp object in JDBC.Assume we have established connection with MySQL database and created a table named dispatch_data using statement object as:Assume we have established connection with MySQL database and ... Read More

Remove Document by ID in MongoDB

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

246 Views

To remove document on the basis of _id in MongoDB, implement the following syntaxdb.yourCollectionName.remove({“_id”:ObjectId(“yourId”});Let us first implement the following query to create a collection with documents>db.removeDocumentOnBasisOfId.insertOne({"UserName":"Larry", "UserAge":23, "UserCountryName":"US"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c986f9f330fd0aa0d2fe4a3") } >db.removeDocumentOnBasisOfId.insertOne({"UserName":"Sam", "UserAge":21, "UserCountryName":"UK"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c986fb4330fd0aa0d2fe4a4") } >db.removeDocumentOnBasisOfId.insertOne({"UserName":"Chris", "UserAge":24, "UserCountryName":"US"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c986fc0330fd0aa0d2fe4a5") } >db.removeDocumentOnBasisOfId.insertOne({"UserName":"Robert", "UserAge":26, "UserCountryName":"UK"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c986fcf330fd0aa0d2fe4a6") } >db.removeDocumentOnBasisOfId.insertOne({"UserName":"David", "UserAge":28, "UserCountryName":"AUS"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c986fed330fd0aa0d2fe4a7") }Following is the query to display all documents from a collection ... Read More

Meaning of AUTO_INCREMENT in MySQL Schema

George John
Updated on 30-Jul-2019 22:30:25

318 Views

In MySQL, AUTO_INCREMENT=3 tells that the inserted record will start from 3 not the default 1. Let us first create a sample table and set auto increment to 3:mysql> create table Auto_incrementDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20)    -> )AUTO_INCREMENT=3; Query OK, 0 rows affected (0.52 sec)Following is the query to insert some records in the table using insert command:mysql> INSERT INTO Auto_incrementDemo(Name) values('John'); Query OK, 1 row affected (0.12 sec) mysql> INSERT INTO Auto_incrementDemo(Name) values('Larry'); Query OK, 1 row affected (0.15 sec) mysql> INSERT INTO Auto_incrementDemo(Name) ... Read More

Convert Java Util Date to Local Date in Any Timezone

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

225 Views

First, set the Date and ZoneId −Date date = new Date(); ZoneId zone = ZoneId.systemDefault();Now convert the java.util.date to localdate −date.toInstant().atZone(zone).toLocalDate() date.toInstant().atZone(zone).toLocalTime() date.toInstant().atZone(zone).getHour() date.toInstant().atZone(zone).getMinute() date.toInstant().atZone(zone).getSecond()Exampleimport java.time.ZoneId; import java.util.Date; public class Demo {    public static void main(String[] args) {       Date date = new Date();       ZoneId zone = ZoneId.systemDefault();       System.out.println("LocalDate = "+date.toInstant().atZone(zone).toLocalDate());       System.out.println("LocalTime= "+date.toInstant().atZone(zone).toLocalTime());       System.out.println("Hour = "+date.toInstant().atZone(zone).getHour());       System.out.println("Minute = "+date.toInstant().atZone(zone).getMinute());       System.out.println("Seconds = "+date.toInstant().atZone(zone).getSecond());    } }OutputLocalDate = 2019-04-18 LocalTime= 23:25:09.708 Hour = 23 Minute = 25 Seconds = 9Read More

Rename All Tables and Columns to Lower Case in MySQL

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

1K+ Views

You can achieve this with the help of INFORMATION_SCHEMA.COLUMNS. The syntax is as follows −SELECT CONCAT('ALTER TABLE ', TABLE_NAME, ' CHANGE `', COLUMN_NAME, '` `', LOWER(COLUMN_NAME), '` ', COLUMN_TYPE, ';') AS anyAliasName FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ‘yourDatabaseName’;Now use the database which has two tables. The database name is as follows “bothinnodbandmyisam”. This database is having the following tables −employeestudentThe description of the employee table is as follows −mysql> desc employee;The following is the output. Let’s say we have the following columns in the employee table which are not in lowercase −+--------------+-------------+------+-----+---------+-------+ | Field        | Type   ... Read More

Clock systemUTC Method in Java

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

269 Views

The current instance of the clock with the UTC time zone can be obtained using the method systemUTC() in the Clock Class in Java. This method requires no parameters and it returns the current instance of the clock with the UTC time zone.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       Clock c = Clock.systemUTC();       Instant i = c.instant();       ZonedDateTime zdt = i.atZone(c.getZone());     System.out.println(zdt.toString()); } }Output2019-02-07T08:00:46.924ZNow let us understand the ... Read More

Advertisements