Object Oriented Programming Articles

Page 341 of 589

Get the location of an element in Java ArrayList

Alshifa Hasnain
Alshifa Hasnain
Updated on 11-Mar-2025 2K+ Views

In this article, we will learn to get the location of an element in Java. In Java, an ArrayList is used for storing and manipulating dynamic collections of elements. When working with an ArrayList, you might need to find the index (position) of a specific element. What is the indexOf()? The location of an element in an ArrayList can be obtained using the method java.util.ArrayList.indexOf(). This method returns the index of the first occurrence of the element that is specified. If the element is unavailable in the ArrayList, then this method returns -1. Syntax int index = arrayList.indexOf(element); Finding the ...

Read More

Java Program for Cocktail Sort

Alshifa Hasnain
Alshifa Hasnain
Updated on 10-Mar-2025 480 Views

In this article, we will learn to perform cocktail sorting in Java. Cocktail Sort, also known as Bidirectional Bubble Sort, is a variation of the standard Bubble Sort algorithm. What is Cocktail Sort? Cocktail Sort works in contrast to bubble sort, wherein elements are iterated from left to right, and the largest element is first brought to its correct position, and so on. In cocktail sort, elements are iterated over in both directions (left and right) in an alternating fashion. Cocktail Sort Working Following are the steps to perform cocktail sort in Java − Traverse ...

Read More

How to create an array of Object in Java

Johar Ali
Johar Ali
Updated on 07-Mar-2025 1K+ Views

In this article, we will learn to create an array of objects in Java. An array of Object classes can be created that can accept any type of object. During the operation on such an array, instanceof operator can be used. Different Approaches The following are the two different approaches to creating an array of objects in Java − Using an Object[] Array Using a Class-Specific Object Array Using an Object[] Array Java provides a built-in Object class, which is the superclass of all classes. This means an array ...

Read More

Java DatabaseMetaData getURL() method with example

Alshifa Hasnain
Alshifa Hasnain
Updated on 06-Mar-2025 582 Views

In this article, we will learn about the DatabaseMetaData getURL() method in Java. The DatabaseMetaData interface provides useful methods to obtain details about the database and the JDBC driver. One such method is getURL(), which returns the URL of the JDBC driver being used. What is the getURL() Method? The getURL() method in Java's DatabaseMetaData interface is used to retrieve the URL of the database to which the current connection is established. Syntax String dbUrl = metaData.getURL(); This method retrieves the URL of the underlying Database Management System and returns it in the form of a String variable. ...

Read More

Java program to map string list to lowercase and sort

Alshifa Hasnain
Alshifa Hasnain
Updated on 03-Mar-2025 863 Views

In this article, we will learn to map a String list to lowercase and sort in Java. We need to manipulate the elements of a list, such as converting all strings to lowercase and sorting them. This is particularly useful when dealing with user input, file processing, or data normalization. Problem Statement Given a list of strings, we want to convert all strings to lowercase and sort the list in reverse alphabetical order.For Example: Input ["Apple", "banana", "Cherry", "date"] Output ["date", "cherry", "banana", "apple"] Using Streams API The Streams API provides a useful and functional approach to processing ...

Read More

Java program to display date and time information in uppercase

Alshifa Hasnain
Alshifa Hasnain
Updated on 03-Mar-2025 751 Views

In this article, we will learn to display the date and time in uppercase using Java. Working with date and time in Java is a common requirement in various applications, logging, scheduling, or data processing. Different Approaches The following are the two different approaches to display the date and time in uppercase using Java − Using Formatter and Calendar Using DateTimeFormatter Using Formatter and Calendar The Formatter class in Java allows us to format date and time using the %Tc specifier. We can then convert the output to uppercase using ...

Read More

Is string a primitive data type or an object in Java?

Alshifa Hasnain
Alshifa Hasnain
Updated on 28-Feb-2025 2K+ Views

In Java there are various data types present, the String type often leads to confusion regarding whether it is a primitive data type or an object(non-primitive data type ).  Primitive Data Types in Java Primitive data types are the most basic data types the Java language provides. Primitive data types are not objects and do not have methods or properties. Eg: int (32-bit), float(32-bit), double(64-bit ), etc.  What is String in Java? A string is not a primitive data type. Java.lang package provides the String class therefore, it is an object type. The String class provides methods to manipulate and operate ...

Read More

Can a final class be subclassed in Java?

Alshifa Hasnain
Alshifa Hasnain
Updated on 27-Feb-2025 2K+ Views

In Java Inheritance is a fundamental feature that allows a class to derive properties and behaviors from another class. In Java, not all classes can be subclassed. A final class is a special type of class that cannot be extended.  What is a Final Class in Java? In Java, a class is declared final using the final keyword. The final modifier for finalizing the implementations of classes, methods, and variables. When a class is marked as final, it means − It cannot be extended. All its methods remain unchanged in their ...

Read More

How to declare a local variable in Java?

Alshifa Hasnain
Alshifa Hasnain
Updated on 27-Feb-2025 1K+ Views

In Java, local variables are those that have been declared within a method, constructor, and block, and are only accessible within that defined scope. Such local variables are used when there is a need to store temporary data during the execution of a program. What is a Local Variable? Local variables are declared in methods, constructors, or blocks. Local variables are created when the method, constructor, or block is entered and the variable will be destroyed once it exits the method, constructor, or block. A local variable is a variable that is − Declared inside ...

Read More

Java ResultSetMetaData getScale() method with example

Alshifa Hasnain
Alshifa Hasnain
Updated on 27-Feb-2025 607 Views

In this article, we will learn the ResultSetMetaData getScale() method in Java. The ResultSetMetaData interface provides metadata about the columns in a ResultSet object. The getScale() method returns the number of digits to the right of the decimal point for a specified column. What is the getScale() method? The getScale() method of the ResultSetMetaData (interface) retrieves the number of digits after the right of the decimal point in the given column. This method accepts an integer value representing the index of a column. and returns an integer value representing the number of digits after the decimal in the specified column. Syntax ...

Read More
Showing 3401–3410 of 5,881 articles
« Prev 1 339 340 341 342 343 589 Next »
Advertisements