karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 15 of 143

How to shuffle an array in Java?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

Declare a string array and add elements in the form of letters −String[] letters = { "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };Convert the above array to list −Listlist = Arrays.asList(letters);Now, create a shuffled array using the Random class object and generate the random letters with nextInt() −int len = list.size(); System.out.println("Shuffled array..."); for (int i = 0; i < letters.length; i++) {    int index = new Random().nextInt(len);    String shuffle = list.get(index);    System.out.println(shuffle); }Exampleimport java.util.Arrays; import java.util.List; import java.util.Random; public class Demo {    public static void main(String[] args) {     ...

Read More

Java Program to generate random number array within a range and get min and max value

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

At first, create a double array −double[] val = new double[10];Now, generate and display random numbers in a loop that loops until the length of the above array. We have used nextInt here for random numbers −for (int i = 0; i < val.length; i++) {    val[i] = new Random().nextInt(100);    System.out.println(val[i]); }Now, get the min and max values. Compare each value of the random array with the MIN and MAX values −double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (int i = 0; i < val.length; i++) {    if (val[i] < min)       min ...

Read More

Java Program to get minimum value with Comparator

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 423 Views

First, declare an integer array and add some elements −Integer arr[] = { 40, 20, 30, 10, 90, 60, 700 };Now, convert the above array to List −List list = Arrays.asList(arr);Now, use Comparator and the reverseOrder() method. Using max() will eventually give you the maximum value, but with reverseOrder() it reverses the result −Comparator comp = Collections.reverseOrder(); System.out.println("Minimum element = "+Collections.max(list, comp));Exampleimport java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; public class Demo {    @SuppressWarnings("unchecked")    public static void main(String args[]) {       Integer arr[] = { 40, 20, 30, 10, 90, 60, 700 };       ...

Read More

Multiple Where clause in C# Linq

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 5K+ Views

Filter collections using Where clause in C#. A single query expression may have multiple where clauses.Firstly, set a collection −IList employee = new List() {    new Employee() { EmpID = 1, EmpName = "Tom", EmpMarks = 90, Rank = 8} ,    new Employee() { EmpID = 2, EmpName = "Anne", EmpMarks = 60, Rank = 21 } ,    new Employee() { EmpID = 3, EmpName = "Jack", EmpMarks = 76, Rank = 18 } ,    new Employee() { EmpID = 4, EmpName = "Amy" , EmpMarks = 67, Rank = 20} , };Now, let’s use multiple ...

Read More

Convert from String to long in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 356 Views

To convert String to long, the following are the two methods.Method 1The following is an example wherein we use parseLong() method.Examplepublic class Demo {    public static void main(String[] args) {       String myStr = "5";       Long myLong = Long.parseLong(myStr);       System.out.println("Long: "+myLong);    } }OutputLong: 5Method 2The following is an example wherein we have used valueOf() and longValue() method to convert String to long.Examplepublic class Demo {    public static void main(String[] args) {       String myStr = "20";       long res = Long.valueOf(myStr).longValue();       System.out.println("Long: "+res);    } }OutputLong: 20

Read More

is_finite() function in PHP

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 93 Views

The is_finite() function checks if a value is finite or not. It Returns true if num is a finite number, else it Returns false.Syntaxis_finite(num)Parametersnum − The number to be checked.ReturnThe is_finite() function Returns true if num is a finite number, else it Returns false.ExampleOutput1Let us see another example −ExampleOutput

Read More

C# program to generate secure random numbers

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

For secure random numbers, use the RNGCryptoServiceProvider Class. It implements a cryptographic Random Number Generator.Using the same class, we have found some random values using the following −using (RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider()) {    byte[] val = new byte[6];    crypto.GetBytes(val);    randomvalue = BitConverter.ToInt32(val, 1); }To generate random secure numbers, you can try to run the following code.Exampleusing System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Security.Cryptography; public class Demo {    public static void Main(string[] args) {       for (int i = 0; i

Read More

Check that the String does not contain certain characters in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 4K+ Views

Let’s say the following is our string with special characters.String str = "test*$demo";Check for the special characters.Pattern pattern = Pattern.compile("[^A-Za-z0-9]"); Matcher match = pattern.matcher(str); boolean val = match.find();Now, if the bool value “val” is true, that would mean the special characters are in the string.if (val == true) System.out.println("Special characters are in the string.");Exampleimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo {    public static void main(String []args) {       String str = "test*$demo";       System.out.println("String: "+str);       Pattern pattern = Pattern.compile("[^A-Za-z0-9]");       Matcher match = pattern.matcher(str);       boolean val = ...

Read More

C# Linq Where Method

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

The Where method filters an array of values based on a predicate.Here, the predicate is checking for elements above 70.Where((n, index) => n >= 70);Exampleusing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       int[] arr = { 10, 30, 20, 15, 90, 85, 40, 75 };       Console.WriteLine("Array:");       foreach (int a in arr)       Console.WriteLine(a);       // getting elements above 70       IEnumerable myQuery = arr.AsQueryable().Where((n, index) => n >= 70);       Console.WriteLine("Elements above 70...:");       foreach (int res in myQuery)       Console.WriteLine(res);    } }OutputArray: 10 30 20 15 90 85 40 75 Elements above 70...: 90 85 75

Read More

Negate a BigInteger in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 253 Views

Use the BigInteger negate() method in Java to negate a BigInteger.First, let us create an object −BigInteger one, two; one = new BigInteger("200");Negate the above and assign it to the second object −two = one.negate();The following is an example −Exampleimport java.math.*; public class BigIntegerDemo {    public static void main(String[] args) {       BigInteger one, two;       one = new BigInteger("200");       System.out.println("Actual Value: " +one);       // negate       two = one.negate();       System.out.println("Negated Value: " +two);    } }OutputActual Value: 200 Negated Value: -200

Read More
Showing 141–150 of 1,421 articles
« Prev 1 13 14 15 16 17 143 Next »
Advertisements