Combine Duplicate Values in MySQL with Hyphen-Separated Corresponding Values

AmitDiwan
Updated on 08-Jul-2020 12:36:56

4K+ Views

To combine, use GROUP_CONCAT() function to combine some attributes in two rows into one. As a separator, use hyphens.Let us first create a table −mysql> create table DemoTable1386    -> (    -> Title varchar(255),    -> Name varchar(60)    -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1386 values('Introduction to MySQL', 'Paul DuBois'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1386 values('Java in Depth', 'Khalid Mughal'); Query OK, 1 row affected (0.48 sec) mysql> insert into DemoTable1386 values('Introduction to MySQL', 'Russell Dyer'); Query OK, ... Read More

Find Closest Pair from Two Sorted Arrays in Java

AmitDiwan
Updated on 08-Jul-2020 12:03:33

350 Views

To find the closest pair from two sorted array, the Java code is as follows −Example Live Demopublic class Demo {    void closest_pair(int my_arr_1[], int my_arr_2[], int arr_1_len, int arr_2_len, int sum){       int diff = Integer.MAX_VALUE;       int result_l = 0, result_r = 0;       int l = 0, r = arr_2_len-1;       while (l=0){          if (Math.abs(my_arr_1[l] + my_arr_2[r] - sum) < diff){             result_l = l;             result_r = r;             ... Read More

Use Until Annotation with Gson Library in Java

raja
Updated on 08-Jul-2020 12:01:11

365 Views

The @Until annotation can use with the setVersion() method of the GsonBuilder class. This annotation can apply to a field in java class and accepts float as an argument. This argument represents the version number in which the field has serialized. The @Until annotation can manage the versioning of JSON classes in web-services.Syntax@Documented @Retention(value=RUNTIME) @Target(value={FIELD, TYPE}) public @interface UntilExampleimport com.google.gson.annotations.Until; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class GsonUntilAnnotationTest {    public static void main(String[] args) {       Employee emp = new Employee();       emp.setEmployeeName("Adithya");       emp.setEmployeeId(115);       emp.setEmployeeTechnology("Python");       emp.setEmploeeAddress("Pune");       ... Read More

Implement Numbering in MySQL Group Concat

AmitDiwan
Updated on 08-Jul-2020 11:58:17

552 Views

Let us first create a table −mysql> create table DemoTable1627     -> (     -> FirstName varchar(20),     -> LastName varchar(20)     -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command.mysql> insert into DemoTable1627 values('John', 'Smith'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1627 values('John', 'Doe'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1627 values('Adam', 'Smith'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1627 values('Carol', 'Taylor'); Query OK, 1 row affected (0.08 sec)Display all records from the table using ... Read More

Find Reminder of Array Multiplication Divided by N in Java

AmitDiwan
Updated on 08-Jul-2020 11:58:16

241 Views

To find reminder of array multiplication divided by n, the Java code is as follows −Example Live Demoimport java.util.*; import java.lang.*; public class Demo{    public static int remainder(int my_arr[], int arr_len, int val){       int mul_val = 1;       for (int i = 0; i < arr_len; i++)       mul_val = (mul_val * (my_arr[i] % val)) % val;       return mul_val % val;    }    public static void main(String argc[]){       int[] my_arr = new int []{ 35, 100, 69, 99, 27, 88, 12, 25 }; ... Read More

Expand a String If Range Is Given in Java

AmitDiwan
Updated on 08-Jul-2020 11:53:10

344 Views

To expand a String if range is given, the Java code is as follows −Example Live Demopublic class Demo {    public static void expand_range(String word) {       StringBuilder my_sb = new StringBuilder();       String[] str_arr = word.split(", ");       for (int i = 0; i < str_arr.length; i++){          String[] split_str = str_arr[i].split("-");          if (split_str.length == 2){             int low = Integer.parseInt(split_str[0]);             int high = Integer.parseInt(split_str[split_str.length - 1]);             while (low

Count Trailing Zeroes in Factorial of a Number in Java

AmitDiwan
Updated on 08-Jul-2020 11:47:03

838 Views

To count trailing zeroes in factorial of a number, the Java code is as follows −Example Live Demoimport java.io.*; public class Demo{    static int trailing_zero(int num){       int count = 0;       for (int i = 5; num / i >= 1; i *= 5){          count += num / i;       }       return count;    }    public static void main (String[] args){       int num = 1000000;       System.out.println("The number of trailing zeroes in " + num +" factorial is " + ... Read More

Count Characters in Each Word of a Given Sentence in Java

AmitDiwan
Updated on 08-Jul-2020 11:43:04

517 Views

To count the characters in each word in a given sentence, the Java code is as follows −Example Live Demoimport java.util.*; public class Demo{    static final int max_chars = 256;    static void char_occurence(String my_str){       int count[] = new int[max_chars];       int str_len = my_str.length();       for (int i = 0; i < str_len; i++)       count[my_str.charAt(i)]++;       char ch[] = new char[my_str.length()];       for (int i = 0; i < str_len; i++){          ch[i] = my_str.charAt(i);          int find = 0;          for (int j = 0; j

Convert Iterator to Spliterator in Java

AmitDiwan
Updated on 08-Jul-2020 11:39:44

145 Views

To convert Iterator to Spliterator, the Java code is as follows −Example Live Demoimport java.util.*; public class Demo{    public static Spliterator getspiliter(Iterator iterator){       return Spliterators.spliteratorUnknownSize(iterator, 0);    }    public static void main(String[] args){       Iterator my_iter = Arrays.asList(56, 78, 99, 32, 100, 234).iterator();       Spliterator my_spliter = getspiliter(my_iter);       System.out.println("The values in the spliterator are : ");       my_spliter.forEachRemaining(System.out::println);    } }OutputThe values in the spliterator are : 56 78 99 32 100 234A class named Demo contains a function named ‘getspiliter’ that returns a spliterator. In ... Read More

Check if Array Digits Can Form a Divisible by 3 Number in Java

AmitDiwan
Updated on 08-Jul-2020 11:37:16

240 Views

To check whether it is possible to make a divisible by 3 number using all digits in an array, the Java code is as follows −Example Live Demoimport java.io.*; import java.util.*; public class Demo{    public static boolean division_possible(int my_arr[], int n_val){       int rem = 0;       for (int i = 0; i < n_val; i++)       rem = (rem + my_arr[i]) % 3;       return (rem == 0);    }    public static void main(String[] args){       int my_arr[] = { 66, 90, 87, 33, 123}; ... Read More

Advertisements