karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 25 of 143

Get the asymmetric difference of two sets in Java

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

Use removeAll() method to get the asymmetric difference of two sets.First set −HashSet set1 = new HashSet (); set1.add("Mat"); set1.add("Sat"); set1.add("Cat");Second set −HashSet set2 = new HashSet (); set2.add("Mat");To get the asymmetric difference −set1.removeAll(set2);The following is an example that displays how to get the asymmetric difference between two sets −Exampleimport java.util.*; public class Demo {    public static void main(String args[]) {       HashSet set1 = new HashSet ();       HashSet set2 = new HashSet ();       set1.add("Mat");       set1.add("Sat");       set1.add("Cat");       System.out.println("Set1 ...

Read More

Display hour in h (1-12 in AM/PM) format in Java

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

The h format in Java Date is like 1-12 hour in AM/ PM. Use SimpleDateFormat("h") to get the same format;// displaying hour in h format SimpleDateFormat simpleformat = new SimpleDateFormat("h"); String strHour = simpleformat.format(new Date()); System.out.println("Hour in h format = "+strHour);Above, we have used the SimpleDateFormat class, therefore the following package is imported −import java.text.SimpleDateFormat;The following is an example −Exampleimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time ...

Read More

C# Enum ToString() Method

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

The ToString() method converts the value of this instance to its equivalent string representation.Firstly, set an enum.enum Vehicle { Car, Bus, Truck, Motobike };To convert it to an equivalent string representation, use ToString().Vehicle.Car.ToString("d")Exampleusing System; public class Demo {    enum Vehicle { Car, Bus, Truck, Motobike };    public static void Main() {       Console.WriteLine("Vehicle.Car = {0}", Vehicle.Car.ToString("d"));       Console.WriteLine("Vehicle.Bus = {0}", Vehicle.Bus.ToString("d"));    } }OutputVehicle.Car = 0 Vehicle.Bus = 1

Read More

Java program to check if binary representations of two numbers are anagram

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

The binary representations of two numbers are anagrams if they have the same number of 0’a and 1’s. An example of this is given as follows −Number 1 = 3 Binary representation of Number 1 = 0011 Number 2 = 12 Binary representation of Number 2 = 1100The two numbers are anagram.A program that demonstrates this is given as follows −Examplepublic class Example { public static void main (String[] args) { long x = 12, y = 3; if(Long.bitCount(x) == Long.bitCount(y)) ...

Read More

Convert an ArrayList to an Array with zero length Array in Java

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

An ArrayList can be converted into an Array using the java.util.ArrayList.toArray() method. This method takes a single parameter i.e. the array of the required type into which the ArrayList elements are stored and it returns an Array that contains all the elements of the ArrayList in the correct order.A program that demonstrates this is given as follows −Exampleimport java.util.ArrayList; import java.util.List; public class Demo {    public static void main(String[] args) {       List aList = new ArrayList();       aList.add("James");       aList.add("Harry");       aList.add("Susan");       aList.add("Emma");       aList.add("Peter"); ...

Read More

What are Add, Remove methods in C# lists?

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

The List is a collection in C# and is a generic collection. The add and remove methods are used in C# lists for adding and removing elements.Let us see how to use Add() method in C#.Exampleusing System; using System.Collections.Generic; class Program {    static void Main() {       List sports = new List();       sports.Add("Football");       sports.Add("Tennis");       sports.Add("Soccer");       foreach (string s in sports) {          Console.WriteLine(s);       }    } }OutputFootball Tennis SoccerLet us see how to use Remove() method in C#.Exampleusing System; ...

Read More

Boolean Literals in Java

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

The Boolean literals have two values i.e. True and False.The following is an example to display Boolean Literals.Examplepublic class Demo {    public static void main(String[] args) {       System.out.println("Boolean Literals");       boolean one = true;       System.out.println(one);       one = false;       System.out.println(one);    } }OutputBoolean Literals true falseIn the above program, we have declared a boolean value and assigned the boolean literal “true”.boolean one = true;In the same way, we have added another boolean literal “false”.one = false;Both of the above values are displayed, which are the boolean literals.

Read More

Get current time information in Java

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

Import the following package for to work with Calendar class in Java, import java.util.Calendar;Create a calendar class now.Calendar cal = Calendar.getInstance();To display entire time information, use the following fields.cal.get(Calendar.HOUR_OF_DAY) cal.get(Calendar.HOUR) cal.get(Calendar.MINUTE) cal.get(Calendar.SECOND) cal.get(Calendar.MILLISECOND)The following is the final example.Exampleimport java.util.Calendar; public class Demo {    public static void main(String[] args) {       Calendar cal = Calendar.getInstance();       // current date and time       System.out.println(cal.getTime().toString());       // time information       System.out.println("Hour (24 hour format) : " + cal.get(Calendar.HOUR_OF_DAY));       System.out.println("Hour (12 hour format) : " + cal.get(Calendar.HOUR));       ...

Read More

Long Date ("D") Format Specifier in C#

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

The "D" format specifier represents a custom date and time format string.The format string is defined by culture's DateTimeFormatInfo.LongDatePattern property.The custom format string is −dddd, dd MMMM yyyyExampleusing System; using System.Globalization; class Demo {    static void Main() {       DateTime myDate = new DateTime(2018, 9, 20);       Console.WriteLine(myDate.ToString("D", CultureInfo.CreateSpecificCulture("en-US")));    } }OutputThursday, September 20, 2018

Read More

Create a Boolean object from Boolean value in Java

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

To create a Boolean object from Boolean value is quite easy. Create an object with Boolean and set the Boolean value “true” or “false”, which are the Boolean literals.Let us now see how “true” value is added.Boolean bool = new Boolean("true");In the same way, “False” value is added.Boolean bool = new Boolean("false");The following is an example displaying how to create a Boolean object from Boolean value.Examplepublic class Demo {    public static void main(String[] args) {       Boolean bool = new Boolean("true");       System.out.println(bool);       bool = new Boolean("false");       System.out.println(bool);    } }OutputTrue False

Read More
Showing 241–250 of 1,421 articles
« Prev 1 23 24 25 26 27 143 Next »
Advertisements