Found 9150 Articles for Object Oriented Programming

Java Program for Case Specific Sorting

Shriansh Kumar
Updated on 01-Aug-2024 10:49:54

817 Views

Suppose you have a String that contains uppercase and lowercase characters both. We have to sort this given string in case specific order which means if the ith position in the given string had an uppercase letter then the newly sorted string must have uppercase letter at that position and same goes for lowercase letters. Also, both lowercase and uppercase letters will be in sorted order separately. In this article, we will try to find the solution for the given problem. First, let's understand the given problem with an example for better understanding. Example Scenario Input: String st = ... Read More

StrictMath subtractExact() in Java With Examples

Shriansh Kumar
Updated on 05-May-2023 18:11:13

167 Views

In java, the subtractExact() is a static method of the class StrictMath. It is available in ‘java.lang’ package. In this article, we will discuss StrictMath and some of its inbuilt methods. We will also see the implementation of subtractExact() method and how it is different from other methods of this class. StrictMath Class in Java StrictMath is a final class that extends object class. We can use its methods without creating instance because all the methods of this class are static and we can call a static method without an object. To call a Static Mehtod Class_name.static_method_name To ... Read More

Java Program for Search an element in a sorted and rotated array

Shriansh Kumar
Updated on 05-May-2023 18:04:44

437 Views

Suppose you have a sorted array with no duplicate values and from a certain index this array is rotated. You have to search for a particular element in it. If it is available in the array then return the index otherwise return -1. In this article, we will solve the given problem using two approaches Linear search and Binary search. Approach 1: Using Linear Search This approach will search for the given element in sequential manner. Algorithm Step 1 − First, declare and initialize an array named ‘araylist’ and an integer variable named ‘searchElem’ that we are going ... Read More

StringJoiner Class vs String.join() Method to Join String in Java

Shriansh Kumar
Updated on 05-May-2023 18:01:43

747 Views

There are numerous ways of joining strings in java. The StringJoiner class and String.join() method are two of them. Both are used to join two or any number of strings but the difference lies in their implementation. In this article, we will try to find the differences that exist in the usage of StringJoiner class and String.join() method. StringJoiner Class It is a class available in java.util package and it is added from JDK 8. We can join multiple strings at a time. Before using, it is necessary to import it into our program using the following command ... Read More

Scanner and nextChar() in Java

Shriansh Kumar
Updated on 05-May-2023 17:59:18

5K+ Views

Scanner is a class available in ‘java.util’ package used to take input from numerous sources like a file, or console. The most common source of taking input is from standard input i.e. keyboard. The scanner class has few methods to take input of primitives and strings from the keyboard. We will understand scanner class and its various methods through this article. Scanner and nextChar() The following methods of Scanner class is used to take input − nextInt() − To take integer as an input. nextLong() − To take long as an input. nextDouble() − To take double as an ... Read More

String Arrays in Java

Shriansh Kumar
Updated on 05-May-2023 17:57:50

1K+ Views

String and Arrays are two distinct things. Array is a linear data structure that is used to store group of elements with similar datatypes but a string is a class in Java that stores a series of characters. Those characters are actually String-type objects. Since strings are objects we can say that string arrays are group of string-type objects. In this article, we will understand string arrays in java and perform some operations on them. String Arrays The string array is a combination of array and string both. Therefore, it has the properties of both array and string such ... Read More

Storage of String in Java

Shriansh Kumar
Updated on 05-May-2023 17:55:07

407 Views

A string is a class in Java that stores a series of characters. Those characters are actually String-type objects. The value of string is enclosed within double quotes. The string class is available in java.lang package. In this article, we will look into the storage mechanism of strings in java. String and Storage of String To create strings − Syntax String nameOfobject = “ values ”; Instance 1 String st1 = “Tutorix and Tutorialspoint”; Here, ‘st1’ is the reference variable and its values are in double quotes. We can also use new keyword to create ... Read More

How to Know whether a Line Touches, Intersects or Lie Outside a Circle in Java?

Mr. Satyabrata
Updated on 04-May-2023 16:39:32

531 Views

A circle is a closed shape formed by tracing a point that moves in a plane such that its distance from a given point is constant. A line is a straight one-dimensional figure that does not have a thickness, and it extends endlessly in both directions. In this article we will check if a given line touches a circle or intersects it using java. We will be given with the centre coordinates and radius of a circle along with equation of the line. We need to check if the given line collides with the circle or not and hence three ... Read More

How to Know If Two Convex Regular Polygons have Same Centre or Not in Java?

Mr. Satyabrata
Updated on 04-May-2023 16:38:01

160 Views

A polygon is a 2-dimensional closed shape that has at least 3 sides. Depending on the number of sides, relationships of the sides and angles, and other characteristics, polygons can be classified under different names like triangles, squares, and quadrilaterals. The convex polygon definition explains that one is a polygon whose angles are all less than 180 degrees each. That also means that the vertices, the point where two sides meet, all point outward from the centre of the shape. In this article, we will find if two convex regular polygons have same centre or not. We will take two ... Read More

How to Confirm If Given Four Points Form a Square in Java?

Mr. Satyabrata
Updated on 04-May-2023 16:36:21

1K+ Views

A square is a two-dimensional shape which has four sides of equal length. The opposite sides of a square are parallel to each other and all four interior angles are right angles with diagonal of equal length. In this article we will check how to confirm if given four points form a square. We will be given a square with four points i.e. A, B, C, D as shown in the figure − We need to check from these points that if they form a square or not. To check this it should satisfy the following condition − ... Read More

Advertisements