AmitDiwan has Published 11365 Articles

How to remove only the first word from columns values with a MySQL query?

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 10:18:51

524 Views

To remove only the first word from column values, use substring(). Following is the syntax −select substring(yourColumnName, locate(' ', yourColumnName)+1) AS anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable (    Title text ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table ... Read More

Remove 20% from stored price in MySQL field, using SQL query?

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 10:16:53

84 Views

Let’s say the stored price is inclusive of 20% sales tax. Now, let us first create a table −mysql> create table DemoTable (    Price int ); Query OK, 0 rows affected (1.09 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(20); Query OK, 1 ... Read More

Streams on Arrays in Java 8

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 09:16:50

299 Views

Stream method of array class introduced in Java 8. Let us see an example wherein we are counting empty strings, eliminating empty strings, getting a list of square of distinct numbers, displaying random numbers, etc −Exampleimport java.util.ArrayList; import java.util.Arrays; import java.util.IntSummaryStatistics; import java.util.List; import java.util.Random; import java.util.stream.Collectors; import java.util.Map; public ... Read More

Convert Iterator to Iterable in Java

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 08:54:51

593 Views

Let’s say the following is our Iterator with Integer values −Iteratoriterator = Arrays.asList(20, 40, 60, 80, 100, 120, 150, 200).iterator();Now, convert the Iterator to Iterable −Iterableiterable = StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, 0), false).collect(Collectors.toList());ExampleFollowing is the program to convert Iterator to Iterable in Java −import java.util.*; import java.util.stream.Collectors; import java.util.stream.StreamSupport; public class Demo { ... Read More

Convert HashSet to TreeSet in Java

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 08:42:45

699 Views

At first, create a HashSet with string values −HashSet hashSet = new HashSet(); hashSet.add("Bradley"); hashSet.add("Katie"); hashSet.add("Brad"); hashSet.add("Amy"); hashSet.add("Ryan"); hashSet.add("Jamie");Now, convert the HashSet to TreeSet −Set set = new TreeSet(hashSet);ExampleFollowing is the program to convert HashSet to TreeSet in Java −import java.util.HashSet; import java.util.Set; import java.util.TreeSet; public class Demo {   ... Read More

Convert Double to Integer in Java

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 08:40:49

647 Views

At first, initialize a double value −double val = 978.65;Now, convert the Double to Integer value using intValue() method −Double d = new Double(val); int res = d.intValue();ExampleFollowing is the program to convert Double to Integer in Java −public class Demo {    public static void main(String args[]) {   ... Read More

Convert an Iterator to Stream in Java

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 08:37:03

293 Views

At first, set an Interator −Iteratoriterator = Arrays.asList(50, 100, 200, 400, 500, 1000).iterator();Now, we have used stream −Streamstream = convertIterator(iterator);Above, the method convertIterator() is used for conversion. Following is the method −public static Stream convertIterator(Iterator iterator) {    return StreamSupport.stream(((Iterable) () -> iterator).spliterator(), false); }ExampleFollowing is the program to ... Read More

Convert a Set of String to a comma separated String in Java

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 08:33:04

787 Views

Let us first create a set with string values −Setset = new HashSet(Arrays.asList("One", "Two", "Three", "Four", "Five", "Six"));Now, convert it to a comma separated string using String.join() −String str = String.join(", ", set);ExampleFollowing is the program to convert set of string to a comma separated string in Java −import java.util.*; ... Read More

Convert a List of String to a comma separated String in Java

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 08:31:37

446 Views

At first, let’s say the following is our List of String −List myList = new ArrayList(Arrays.asList("One", "Two", "Three", "Four"));Now, convert this to a comma separated string using String.join()String str = String.join(", ", myList);ExampleFollowing is the program to convert List of String to a comma separated String in Java −import java.util.*; ... Read More

Conversion of Java Maps to List

AmitDiwan

AmitDiwan

Updated on 25-Sep-2019 08:28:23

109 Views

At first, let us create a Java Map and initialize −Map map = new HashMap(); map.put(1, "Tom"); map.put(2, "John"); map.put(3, "Kevin"); map.put(4, "Jacob"); map.put(5, "Ryan");Now, convert the Map to List −ArrayList key = new ArrayList(map.keySet()); ArrayList value = new ArrayList(map.values());ExampleFollowing is the program to convert Maps to List in Java ... Read More

Advertisements