Articles on Trending Technologies

Technical articles with clear explanations and examples

Find the first repeated word in a string in Java

AmitDiwan
AmitDiwan
Updated on 08-Jul-2020 1K+ Views

To find the first repeated word in a string in Java, the code is as follows −Example Live Demoimport java.util.*; public class Demo{    static char repeat_first(char my_str[]){       HashSet my_hash = new HashSet();       for (int i=0; i

Read More

Find the uncommon values concatenated from both the strings in Java

AmitDiwan
AmitDiwan
Updated on 08-Jul-2020 313 Views

To find the uncommon values concatenated from both the strings in Java, the code is as follows −Example Live Demoimport java.util.*; import java.lang.*; import java.io.*; public class Demo{    public static String concat_str(String str_1, String str_2){       String result = "";       int i;       HashMap my_map = new HashMap();       for (i = 0; i < str_2.length(); i++)       my_map.put(str_2.charAt(i), 1);       for (i = 0; i < str_1.length(); i++)       if (!my_map.containsKey(str_1.charAt(i)))       result += str_1.charAt(i);       else       ...

Read More

How to find all tables that contains columnA and columnB in MySQL?

AmitDiwan
AmitDiwan
Updated on 08-Jul-2020 182 Views

To find specific column names, use information_schema.columns Here, I am using Id in place of columnA and Name in place of columnB −mysql> select table_name as TableNameFromWebDatabase    -> from information_schema.columns    -> where column_name IN ('Id', 'Name')    -> group by table_name    -> having count(*) = 3;This will produce the following output. Following are the table with columns Id and Name −+--------------------------+ | TableNameFromWebDatabase | +--------------------------+ | student                  | | distinctdemo             | | secondtable              | | groupconcatenatedemo   ...

Read More

How to convert bean to JSON object by excluding some properties using JsonConfig in Java?

raja
raja
Updated on 08-Jul-2020 1K+ Views

The JsonConfig class is a utility class that helps to configure the serialization process. We can convert a bean to a JSON object with few properties that can be excluded using the setExcludes() method of JsonConfig class and pass this JSON config instance to an argument of static method fromObject() of JSONObject.Syntaxpublic void setExcludes(String[] excludes)In the below example, we can convert bean to a JSON object by excluding some of the properties.Exampleimport net.sf.json.JSONObject; import net.sf.json.JsonConfig; public class BeanToJsonExcludeTest {    public static void main(String[] args) {       Student student = new Student("Raja", "Ramesh", 35, "Madhapur");       JsonConfig jsonConfig = new ...

Read More

MySQL query to count the dates and fetch repeated dates as well

AmitDiwan
AmitDiwan
Updated on 08-Jul-2020 245 Views

To display the count, use aggregate function COUNT(*). Let us first create a table −mysql> create table DemoTable1321 -> ( -> ArrivalDatetime timestamp -> ); Query OK, 0 rows affected (0.50 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable1321 values(now()); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1321 values('2019-01-10 12:34:00'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1321 values('2019-06-12 11:34:00'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1321 values('2019-06-12 04:50:00'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1321 values('2019-09-18 10:50:45'); Query OK, 1 ...

Read More

How to search dob in a table, which is in the yyyy-mm-dd structure and compare only with a specific yyyy format (year) in MySQL?

AmitDiwan
AmitDiwan
Updated on 08-Jul-2020 181 Views

For this, use MySQL YEAR() as in the below syntax −select * from yourTableName where year(yourColumnName)=’yourYearValue’;Let us first create a table −mysql> create table DemoTable1322 -> ( -> DOB date -> ); Query OK, 0 rows affected (0.55 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable1322 values('1999-04-12'); Query OK, 1 row affected (0.68 sec) mysql> insert into DemoTable1322 values('2010-12-01'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1322 values('2015-03-09'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable1322 values('2007-05-24'); Query OK, 1 row affected (0.08 sec)Display all records from the table ...

Read More

Anchor Pseudo-classes in CSS

AmitDiwan
AmitDiwan
Updated on 08-Jul-2020 1K+ Views

Using CSS pseudo-class selectors, namely, :active, :hover, :link and :visited we can style different states of a link/anchor. For proper functionality, the order of these selectors should be −:link:visited:hover:activeThe syntax of CSS psudo-class property is as follows −a:(pseudo-selector) {    /*declarations*/ }ExampleLet’s see an example to use CSS Anchor Pseudo Classes − Live Demo div {    display: flex;    float: left; } a {    margin: 20px;    padding: 10px;    border: 2px solid black;    text-shadow: -1px 0px black, 0px -1px black, 0px 1px black, 1px 0px black;    font-size: 1.1em; } a:link {    text-decoration: ...

Read More

Find the final X and Y when they are Altering under given condition in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 08-Jul-2020 139 Views

Consider we have the initial values of two positive integers X and Y. Find the final value of X and Y, such that there will be some alteration as mentioned below −step1 − If X = 0 and Y = 0 then terminate the process, otherwise go to step2step2 − If X >= 2Y, then set X = X – 2Y, and go to step1, otherwise go to step3step3 − If Y >= 2X, then set Y = Y – 2X, and go to step1, otherwise end the process.The number X and Y will be in range [0 and 1018] ...

Read More

How to add elements to JSON Object using JSON-lib API in Java?

raja
raja
Updated on 08-Jul-2020 3K+ Views

The JSON-lib is a Java library for serializing and de-serializing java beans, maps, arrays, and collections in JSON format. We can add elements to the JSON object using the element() method of JSONObject class. We need to download all the dependent jars like json-lib.jar, ezmorph.jar, commons-lang.jar, commons-collections.jar, commons-beanutils.jar, and commons-logging.jar and can import net.sf.json package in our java program to execute it.Syntaxpublic JSONObject element(String key, Object value) - put a key/value pair in the JSONObject Exampleimport java.util.Arrays; import net.sf.json.JSONObject; public class JsonAddElementTest {    public static void main(String[] args) {       JSONObject jsonObj = new JSONObject()          .element("name", "Raja ...

Read More

How to serialize and deserialize a JSON using the ExclusionStrategy interface in Java?

raja
raja
Updated on 08-Jul-2020 767 Views

The ExclusionStrategy interface can be used to exclude any field during serialization and deserialization. We can provide a custom implementation of the ExclusionStrategy interface and need to register it with GsonBuilder using the setExclusionStrategies() method. It configures Gson to apply a set of exclusion strategies during serialization and deserialization.Syntaxpublic GsonBuilder setExclusionStrategies(ExclusionStrategy... strategies)Exampleimport com.google.gson.*; import com.google.gson.ExclusionStrategy; import com.google.gson.FieldAttributes; public class ExclusionStrategyTest {    public static void main(String args[]) throws Exception {       Gson gson = new GsonBuilder().setExclusionStrategies(new CustomExclusionStrategy()).create();          Person person = new Person();          person.setFirstName("Adithya");          person.setLastName("Sai");          person.setAddress("Hyderabad");     ...

Read More
Showing 40981–40990 of 61,248 articles
Advertisements