Found 9326 Articles for Object Oriented Programming

What does the method equals(obj[] a1, obj[] a2) do in java?

Lakshmi Srinivas
Updated on 20-Feb-2020 12:46:45

127 Views

The equals(Object[] a, Object[] a2) method of the java.util.Arrays class returns true if the two specified arrays of objects are equal to one another. The two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. Two objects e1 and e2 are considered equal if (e1==null ? e2==null : e1.equals(e2)). The two arrays are equal if they contain the same elements in the same order. Two array references are considered equal if both are null.Exampleimport java.util.Arrays; public class ArrayDemo {    public static void main(String[] ... Read More

What does the method equals(int[] a1, int[] a2) do in java?

Monica Mona
Updated on 20-Feb-2020 12:46:02

207 Views

The equals(int[] a, int[] a2) method of java.util.Arrays returns true if the two specified arrays of integers are equal to one another. Two arrays are equal if they contain the same elements in the same order. Two array references are considered equal if both are null.Exampleimport java.util.Arrays; public class ArrayDemo {    public static void main(String[] args) {       int[] arr1 = new int[] { 10, 12, 5, 6 };       int[] arr2 = new int[] { 10, 12, 5, 6 };       int[] arr3 = new int[] { 10, 5, 6, 12 };     ... Read More

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

karthikeya Boyini
Updated on 25-Feb-2020 08:21:52

78 Views

The fill(object[] a, int fromIndex, int toIndex, object val) method of the class java.util.Arrays assign the specified Object reference to each element of the specified range of the specified array of objects. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be filled is empty)Exampleimport java.util.Arrays; public class ArrayDemo {    public static void main(String[] args) {       Object arr[] = new Object[] {1.2, 5.6, 3.4, 2.9, 9.7};       System.out.println("Actual values: ");       for (Object value : arr) {          System.out.println("Value ... Read More

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

Swarali Sree
Updated on 25-Feb-2020 09:27:53

126 Views

The fill(int[] a, int fromIndex, int toIndex, int val) method of the java.util.Arrays class assigns the specified int value to each element of the specified range of the specified array of integers. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive.(If fromIndex==toIndex, the range to be filled is empty.)Exampleimport java.util.Arrays; public class ArrayDemo {    public static void main(String[] args) {       int arr[] = new int[] {1, 6, 3, 2, 9};       System.out.println("Actual values: ");       for (int value : arr) {          System.out.println("Value = ... Read More

What does the method fill(int[], int val) do in java?

Samual Sam
Updated on 20-Feb-2020 12:42:04

87 Views

The fill(int[] a, int val) method of the java.util.Arrays class assigns the specified int value to each element of the specified array of integers.Exampleimport java.util.Arrays; public class ArrayDemo {    public static void main(String[] args) {       int arr[] = new int[] {1, 6, 3, 2, 9};       System.out.println("Actual values: ");       for (int value : arr) {          System.out.println("Value = " + value);       }       Arrays.fill(arr, 18);       System.out.println("New values after using fill() method: ");       for (int value : arr) {          System.out.println("Value = " + value);       }    } }OutputActual values: Value = 1 Value = 6 Value = 3 Value = 2 Value = 9 New values after using fill() method: Value = 18 Value = 18 Value = 18 Value = 18 Value = 18

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

Sai Subramanyam
Updated on 30-Jul-2019 22:30:21

83 Views

The toString(Object[] a) method of the java.util.Arrays class returns a string representation of the contents of the specified Object array. If the array contains other arrays of elements, they are converted to strings by the Object.toString() method inherited from Object, which describes their identities rather than their contents. Example import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { Object[] ob1 = new Object[] { 10, 20 }; System.out.println("The array is:"); for (Object number ... Read More

According to Java Operator precedence, which operator has the highest precedence?

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

513 Views

Operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator.Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedence operators will be evaluated first.CategoryOperatorAssociativityPostfix>() [] . (dot operator)Left to rightUnary>++ - - ! ~Right to leftMultiplicative>* /Left to rightAdditive>+ -Left to rightShift>>> >>> >= < == !=Left to rightBitwise AND>&Left to rightBitwise XOR>^Left to rightBitwise OR>|Left to ... Read More

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

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

75 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

812 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

62 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

Advertisements