Found 9119 Articles for Object Oriented Programming

What does the method sort(obj[] a, int fromIndex, int toIndex) do in java?

Monica Mona
Updated on 20-Feb-2020 12:34:40

109 Views

The java.util.Arrays.sort(Object[] a, int fromIndex, int toIndex) method sorts the specified range of the specified array of objects into ascending order, according to the natural ordering of its elements. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive.Exampleimport java.util.Arrays; public class ArrayDemo {    public static void main(String[] args) {       Object ob[] = {27, 11, 5, 44};       for (Object number : ob) {          System.out.println("Number = " + number);       }       Arrays.sort(ob, 1, 3);       System.out.println("Object array ... Read More

What is the type conversion operator ( ) in Java and how to use it?

karthikeya Boyini
Updated on 20-Feb-2020 10:09:52

939 Views

Cast operator in java is used to convert one data type to other.Examplepublic class Sample {    public static void main(String args[]) {       double d = 20.3;       int i = (int)d;       System.out.println(i);    } }Output20

What does the method sort(int[] a, int fromIndex, int toIndex) do in java?

karthikeya Boyini
Updated on 20-Feb-2020 12:33:49

122 Views

The sort(int[] a, int fromIndex, int toIndex) method of the java.util.Arrays class sorts the specified range of the specified array of integer value into ascending numerical order. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive.Exampleimport java.util.Arrays; public class ArrayDemo {    public static void main(String[] args) {       int iArr[] = {3, 1, 2, 18, 10};       for (int number : iArr) {          System.out.println("Number = " + number);       }       Arrays.sort(iArr, 0, 3);       System.out.println("int array with some ... Read More

What does the method sort(obj[] a) do in java?

Sharon Christine
Updated on 25-Feb-2020 09:28:44

118 Views

The sort(Object[]) method of the java.util.Arrays class sorts the specified array of Objects into ascending order according to the natural ordering of its elements.Exampleimport java.util.Arrays; public class ArrayDemo {    public static void main(String[] args) {       Object ob[] = {27, 11, 44};       for (Object number : ob) {          System.out.println("Number = " + number);       }       Arrays.sort(ob);       System.out.println("The sorted Object array is:");       for (Object number : ob) {          System.out.println("Number = " + number);       }    } }OutputNumber = 27 Number = 11 Number = 44 The sorted Object array is: Number = 11 Number = 27 Number = 44

How to use the instanceof operator in Java?

Sharon Christine
Updated on 20-Feb-2020 10:07:53

246 Views

The instanceof operator is used only for object reference variables. The operator checks whether the object is of a particular type (class type or interface type).Examplepublic class Test {    public static void main(String args[]) {       String name = "James";       boolean result = name instanceof String;       System.out.println(result);    } }Outputtrue

What does the method sort(int[] a) do in java?

Swarali Sree
Updated on 13-Jun-2020 11:56:46

110 Views

The sort(int[]) method of the java.util.Arrays class sorts the specified array of integer values into ascending numerical order.Exampleimport java.util.Arrays; public class ArrayDemo {    public static void main(String[] args) {       int iArr[] = {2, 1, 9, 6, 4};       for (int number : iArr) {          System.out.println("Number = " + number);       }       Arrays.sort(iArr);       System.out.println("The sorted int array is:");       for (int number : iArr) {          System.out.println("Number = " + number);       }    } }Output Number = 2 Number = 1 Number = 9 Number = 6 Number = 4 The sorted int array is: Number = 1 Number = 2 Number = 4 Number = 6 Number = 9

What is the conditional operator ?: in Java?

Swarali Sree
Updated on 20-Feb-2020 10:06:14

14K+ Views

The conditional operator is also known as the ternary operator. This operator consists of three operands and is used to evaluate Boolean expressions. The goal of the operator is to decide; which value should be assigned to the variable. The operator is written as:variable x = (expression)? value if true: value if falseExamplepublic class Test {    public static void main(String args[]) {       int a, b;       a = 10;       b = (a == 1) ? 20: 30;       System.out.println("Value of b is: " + b);       b = (a == 10) ? 20: 30;       System.out.println(“Value of b is: " + b);    } }OutputValue of b is: 30 Value of b is: 20

What does the bitwise right shift operator do in Java?

Lakshmi Srinivas
Updated on 30-Jul-2019 22:30:21

359 Views

The left operand value is moved right by the number of bits specified by the right operand.Example: A >> 2 = 15 means 1111.

What does the bitwise left shift operator do in Java?

Monica Mona
Updated on 30-Jul-2019 22:30:21

244 Views

The left operand value is moved left by the number of bits specified by the right operand.Example: A

What are the bitwise zero fill right shift zero operators in Java?

Debarpito Sarkar
Updated on 05-Sep-2022 09:15:05

3K+ Views

This article will help you understand all about Bitwise Zero Fill Right Shift Zero Operators in Java. Note that Bitwise Zero Fill Right Shift Zero Operator is same as Bitwise Zero Fill Right Shift Operator. Before understanding right shift operators, let us revise about Operators. OPERATORS In computer programming we often need to perform some arithmetical or logical operations. In such circumstances, we need operators to perform these tasks. Thus, an Operator is basically a symbol or token, which performs arithmetical or logical operations and gives us meaningful result. The values involved in the operation are called Operands. In this ... Read More

Advertisements