karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

1,421 articles

How to convert Javascript dictionary to Python dictionary?

karthikeya Boyini
karthikeya Boyini
Updated on 01-Sep-2025 2K+ Views

Python Dictionary In Python, a dictionary is a collection of unique key-value pairs. Unlike lists, which use numeric indexing, dictionaries use immutable keys like strings, numbers, or tuples. Lists cannot be keys since they are mutable. Dictionaries are created using {} and store, retrieve, or delete values using their keys. The list() function returns all keys, sorting them. The in keyword checks for key existence, and replacing a key updates its value. Converting JavaScript to a Python Dictionary Python and JavaScript represent dictionaries differently, so an intermediate format is needed to exchange data between them. The most widely used format ...

Read More

Get the union of two sets in Java

karthikeya Boyini
karthikeya Boyini
Updated on 28-Jan-2025 7K+ Views

The union of two sets combines all the unique elements from both sets into one. In Java we can achieve this using the HashSet class, which ensures no duplicate elements. This article will demonstrate two approaches to finding the union of two sets.  Different Approaches  Following are the two different approaches to getting the union of two sets in Java − Using the addAll() Method Using Streams Using the addAll() Method The simplest way to find the union of two sets is by using the addAll() method of the HashSet class. This ...

Read More

Java Program to display Frame after some seconds

karthikeya Boyini
karthikeya Boyini
Updated on 02-Jan-2025 499 Views

In this article, we will learn how to display a frame after a few seconds in Java using the Timer class. This example shows how to delay the visibility of a frame by 2 seconds using Swing. Timer() class The Timer class is used to schedule tasks that execute after a specific time interval or repeatedly at regular intervals. It allows tasks to be run by a thread that handles the scheduling and execution. Each task can be set to execute either once or repeatedly at fixed intervals. The execution of all tasks is managed by a background thread associated ...

Read More

Java program to convert a Map to a read only map

karthikeya Boyini
karthikeya Boyini
Updated on 31-Dec-2024 728 Views

A read-only map in Java is a type of Map that cannot be modified after it has been created. This means that once the map has been set to be read-only, we cannot add, remove, or update any of the key-value pairs.Converting a Map to a read only map We can convert a mutable map to an immutable map, a read-only map using the Collections.unmodifiableMap() method. This method provides a way to make sure that the map cannot be modified once it has been wrapped in this method. Following are the steps to convert a Map to a read-only map ...

Read More

Java Program to convert from a java.util.Date Object to a java.sql.Date Object

karthikeya Boyini
karthikeya Boyini
Updated on 23-Dec-2024 770 Views

In this article, we will learn to convert a java.util.Date object to a java.sql.Date object in Java. This is a common requirement when working with databases, as many database systems use the java.sql.Date class to represent date values. While java.util.Date is used for general date and time representation in Java, java.sql.Date is specifically designed to handle SQL-compatible date formats. java.util.Date  The Date class in the java.util package representing a specific moment in time, measured in milliseconds since January 1, 1970, UTC (the "epoch"). It's a general-purpose date and time representation. java.sql.Date A subclass of ...

Read More

strdup() and strdndup() in C/C++

karthikeya Boyini
karthikeya Boyini
Updated on 03-Dec-2024 8K+ Views

strdup() The function strdup() is used to duplicate a string. It returns a pointer to a null-terminated byte string. Syntax Here is the syntax of strdup() in C language, char *strdup(const char *string); Example Here is an example of strdup() in C language. #include #include int main() {  char *str = "Helloworld";  char *result;  result = strdup(str);  printf("The string : %s", result);  return 0; } Output The string : Helloworld strndup() The function strndup works similarly to the function strndup(). This function duplicates the string at most size bytes i.e. the given size in the function. It also returns ...

Read More

Java program to add and remove elements from a set which maintains the insertion order

karthikeya Boyini
karthikeya Boyini
Updated on 19-Nov-2024 720 Views

In this article, we will learn how to use a LinkedHashSet in Java to add and remove elements while maintaining the insertion order. You will see how elements are stored, removed, and updated in a LinkedHashSet without altering the sequence in which they were added. Problem Statement Write a Java program to add elements to a LinkedHashSet, remove specific elements, and display the updated set while ensuring the insertion order of the elements remains unchanged. Below is a demonstration of the same − Input Set = [20, 60, 80, 120, 150, 200, 220, 260, 380] Output Set = [20, 60, ...

Read More

Java program to get the current value of the system timer in nanoseconds

karthikeya Boyini
karthikeya Boyini
Updated on 18-Nov-2024 427 Views

In this article, we use the System.nanoTime() method in Java to get the current value of the system timer in nanoseconds. It returns the current value of the most precise available system timer, in nanoseconds. Problem StatementGiven that you need to get the current value of the system timer in nanoseconds, write a Java program that retrieves this value using the System.nanoTime() method.Input There is no specific input as the program retrieves the system's current time in nanoseconds directly.Output Current Value: 49908709882168 nanoseconds Steps to get the current value of the system timer in nanosecondsThe following are the ...

Read More

Java program to generate a random number from an array

karthikeya Boyini
karthikeya Boyini
Updated on 04-Nov-2024 6K+ Views

In this article, we will learn how to generate a random number from an array of integers in Java by using Random class. The Random class provides methods to generate random numbers, and we will use the nextInt(int bound) method to get a random index within the bounds of our array length. Problem Statement Given an array of integers, we need to randomly select and display one element from the array using Java. Input arr = { 10, 30, 45, 60, 78, 99, 120, 140, 180, 200}; Output Random number from the array = 30 Steps to generate ...

Read More

Java program to put value to a Properties list

karthikeya Boyini
karthikeya Boyini
Updated on 30-Oct-2024 460 Views

In this article, we will learn how to use the Properties class in Java to store and display key-value pairs. The Properties class is useful for handling configuration settings or storing data in a structured way, where both keys and values are strings. By using the put() method, we can easily add values to a property list and later retrieve or display these key-value pairs. This approach provides a simple and efficient way to manage data in a key-value format in Java applications. Problem Statement A properties list contains country-year pairs. Write a Java program to store values ...

Read More
Showing 1–10 of 1,421 articles
« Prev 1 2 3 4 5 143 Next »
Advertisements