Programming Articles

Page 794 of 2544

Get the Component Type of an Array Object in Java

Anvi Jain
Anvi Jain
Updated on 11-Mar-2026 2K+ Views

In order to get the component type of an Array Object in Java, we use the getComponentType() method. The getComponentType() method returns the Class denoting the component type of an array. If the class is not an array class this method returns null.Declaration − The java.lang.Class.getComponentType() method is declared as follows -public Class getComponentType()Let us see a program to the get the component type of an Array Object in Java -Examplepublic class Example {    public static void main(String[] args) {       int[] array = new int[] {1, 2, 3};       // obtain the Class of ...

Read More

C# Linq Last() Method

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

Get the last element from a sequence using the Linq Last() method.The following is our array.int[] val = { 10, 20, 30, 40 };Now, get the last element.val.AsQueryable().Last();Exampleusing System; using System.Collections.Generic; using System.Linq; class Demo {    static void Main() {       int[] val = { 10, 20, 30, 40 };       // getting last element       int last_num = val.AsQueryable().Last();       Console.WriteLine("Last element: "+last_num);    } }OutputLast element: 40

Read More

Get the class name for various objects in Java

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 399 Views

The getName() method is used to get the names of the entities such as interface, class, array class, void etc. that are represented by the class objects. These names are returned in the form of a string. The getPackage() method gets the package for the given class.A program that gets the class name for various objects is given as follows −Examplepackage Test; import java.io.IOException; import java.util.HashMap; public class Demo {    public static void main(String args[]) throws IOException {       Object obj = "string";       System.out.println("The class name is: " + obj.getClass().getName());       obj ...

Read More

Change date formatting symbols in Java

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

For date formatting symbols, use the DateFormatSymbols class.Firstly, set weekdays using a string arrayString[] weekDays2 = { "", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" };Now, set short week days withDateFormatSymbols mySymbols = new DateFormatSymbols(); mySymbols.setShortWeekdays(weekDays2);Get the date −dateFormat = new SimpleDateFormat("EEEE, dd MMM yyyy", mySymbols); System.out.println(dateFormat.format(new Date()));The following is an example −Exampleimport java.text.SimpleDateFormat; import java.text.DateFormat; import java.text.DateFormatSymbols; import java.util.Date; public class Demo {    public static void main(String[] args) {       String[] weekDays1 = { "", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };       String[] weekDays2 = { "", "monday", "tuesday", "wednesday", "thursday", "friday", ...

Read More

Get Canonical Name for a class in Java

Nancy Den
Nancy Den
Updated on 11-Mar-2026 497 Views

The canonical name of a class can be obtained using the java.lang.Class.getCanonicalName() method. This method returns the canonical name of the underlying class and returns null if there is no canonical name for the underlying class.A program that demonstrates the getCanonicalName() method to obtain the canonical name is given as follows −Examplepackage Test; import java.lang.*; public class Demo {    public static void main(String[] args) {       Demo obj = new Demo();       Class c = obj.getClass();       System.out.println("The canonical name of the underlying Class is: " + c.getCanonicalName());    } }OutputThe canonical name ...

Read More

C# Enum Equals Method

George John
George John
Updated on 11-Mar-2026 788 Views

To find the equality between enums, use the Equals() method.Let’s say we have the following Enum.enum Products { HardDrive, PenDrive, Keyboard};Create two Products objects and assign the same values.Products prod1 = Products.HardDrive; Products prod2 = Products.HardDrive;Now check for equality using Equals() method. It would be True since both have the same underlying value.Exampleusing System; class Program {    enum Products {HardDrive, PenDrive, Keyboard};    enum ProductsNew { Mouse, HeadPhone, Speakers};    static void Main() {       Products prod1 = Products.HardDrive;       Products prod2 = Products.HardDrive;       ProductsNew newProd1 = ProductsNew.HeadPhone;       ProductsNew ...

Read More

Java program to print all distinct elements of a given integer array in Java

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

All distinct elements of an array are printed i.e. all the elements in the array are printed only once and duplicate elements are not printed. An example of this is given as follows.Array = 1 5 9 1 4 9 6 5 9 7 Distinct elements of above array = 1 5 9 4 6 7A program that demonstrates this is given as follows.Examplepublic class Example {    public static void main (String[] args) {       int arr[] = {1, 5, 9, 1, 4, 9, 6, 5, 9, 7};       int n = arr.length;     ...

Read More

Convert.ToUInt32 Method in C#

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

Convert a specified value to a 32-bit unsigned integer using the Convert.ToUInt32 method.The following is our string.string str = "210";Now, let us convert it to a 32-bit unsigned integer.uint res; res = Convert.ToUInt32(str);Exampleusing System; public class Demo {    public static void Main() {       string str = "210";       uint res;       res = Convert.ToUInt32(str);       Console.WriteLine("Converted string '{0}' to {1}", str, res);    } }OutputConverted string '210' to 210

Read More

Java Program to list Short Weekday Names

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

To list short weekday names, use the getShortWeekdays() from the DateFormatSymbols class in Java.DateFormatSymbols is a class for encapsulating localizable date-time formatting data.Get short weekday names in an arrayString[] days = new DateFormatSymbols().getShortWeekdays();Display the weekdayfor (int i = 0; i < days.length; i++) { String weekday = days[i]; System.out.println(weekday); }The following is an example −Exampleimport java.text.DateFormatSymbols; public class Demo {    public static void main(String[] args) {       String[] days = new DateFormatSymbols().getShortWeekdays();       for (int i = 0; i < days.length; i++) {          String weekday = days[i];          System.out.println(weekday);       }    } }OutputSun Mon Tue Wed Thu Fri Sat

Read More

Use reflection to create, fill, and display an array in Java

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 279 Views

An array is created using the java.lang.reflect.Array.newInstance() method. This method basically creates a new array with the required component type as well as length.The array is filled using the java.lang.reflect.Array.setInt() method. This method sets the required integer value at the index specified for the array.The array displayed using the for loop. A program that demonstrates this is given as follows −Exampleimport java.lang.reflect.Array; public class Demo {    public static void main (String args[]) {       int arr[] = (int[])Array.newInstance(int.class, 10);       int size = Array.getLength(arr);       for (int i = 0; i

Read More
Showing 7931–7940 of 25,433 articles
« Prev 1 792 793 794 795 796 2544 Next »
Advertisements