AmitDiwan has Published 10740 Articles

Traverse through a HashMap in Java

AmitDiwan

AmitDiwan

Updated on 20-Sep-2019 11:25:42

2K+ Views

To traverse through a HashMap, use Iterator. The HashMap class uses a hashtable to implement the Map interface. This allows the execution time of basic operations, such as get( ) and put( ), to remain constant even for large sets.Following is the code to traverse through a HashMap −Exampleimport java.util.*; ... Read More

The new operator in Java

AmitDiwan

AmitDiwan

Updated on 20-Sep-2019 11:23:09

7K+ Views

The new operator is used in Java to create new objects. It can also be used to create an array object.Let us first see the steps when creating an object from a class −Declaration − A variable declaration with a variable name with an object type.Instantiation − The 'new' keyword ... Read More

HTML DOM Textarea name Property

AmitDiwan

AmitDiwan

Updated on 20-Sep-2019 11:18:43

141 Views

The HTML DOM Textarea defaultValue property returns and modify the value of name attribute of a text area element in an HTML document.SyntaxFollowing is the syntax −1. Returning nameobject.name2. Adding nameobject.name = “text”Let us see an example of HTML DOM Textarea name Property:Example    body {     ... Read More

Nested Classes in Java

AmitDiwan

AmitDiwan

Updated on 20-Sep-2019 11:09:52

2K+ Views

Writing a class within another is allowed in Java. The class written within is called the nested class, and the class that holds the inner class is called the outer class. Nested classes are divided into two types −Non-static nested classes (Inner Classes) − These are the non-static members of a class.Static ... Read More

Java Integer compareUnsigned() method

AmitDiwan

AmitDiwan

Updated on 20-Sep-2019 11:06:25

237 Views

The compareUnsigned() method compares two integer objects numerically considering the values as unsigned.The return value if 0 if both values are equal; -1 if the val1is less than val2. The return value is 1, if the val1 is more than val2.At first, set two Integer objects −int val1 = 50; ... Read More

Java Integer compareTo() method

AmitDiwan

AmitDiwan

Updated on 20-Sep-2019 11:05:01

8K+ Views

The java.lang.Integer.compareTo() method compares two Integer objects numerically. This method returns the value 0 if this Integer is equal to the argument Integer, a value less than 0 if this Integer is numerically less than the argument Integer and a value greater than 0 if this Integer is numerically greater than the ... Read More

Java Integer byteValue() method

AmitDiwan

AmitDiwan

Updated on 20-Sep-2019 11:01:11

239 Views

The byteValue() method returns the value of this Integer as a byte.Following is an example to implement the byteValue() method in Java −Examplepublic class Main {    public static void main(String[] args) {       Integer val = new Integer(10);       byte res = val.byteValue();     ... Read More

Java Integer bitCount() method

AmitDiwan

AmitDiwan

Updated on 20-Sep-2019 10:58:54

229 Views

The java.lang.Integer.bitCount() method returns the number of one-bits in the two's complement binary representation of the specified int value.At first, set an int value −int val = 210;Now, find the number of one-bits −Integer.bitCount(val)Following is an example to implement the bitCount() method in Java −Examplepublic class Main {    public static void ... Read More

Check if a value is present in an Array in Java

AmitDiwan

AmitDiwan

Updated on 20-Sep-2019 10:57:19

857 Views

At first sort the array −int intArr[] = {55, 20, 10, 60, 12, 90, 59}; // sorting array Arrays.sort(intArr);Now, set the value to be searched in an int variable −int searchVal = 12;Check for the presence of a value in an array −int retVal = Arrays.binarySearch(intArr, searchVal); boolean res = ... Read More

Check if a String starts with any of the given prefixes in Java

AmitDiwan

AmitDiwan

Updated on 20-Sep-2019 10:54:48

550 Views

Let’s say the string is −String str = "Malyalam";Let’s say the prefixes are in an array −String[] prefixArr = { "Ga", "Ma", "yalam" };Now, to check whether the string starts with any of the abive prefix, use the startsWith() −if (Stream.of(prefixArr)    .anyMatch(str::startsWith))    System.out.println("TRUE"); else    System.out.println("FALSE");Following is an ... Read More

Advertisements