- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4338 Articles for Java 8
3K+ Views
The contains() function of the Ints class is used to check whether an element is present in the array or not.Following is the syntax −public static boolean contains(int[] arr, int target)Here, arr is the array wherein the element is to be checked. The target is the element to be checked.Following is an example to implement the contains() method of the Ints class −Exampleimport com.google.common.primitives.Ints; import java.util.*; class Demo { public static void main(String[] args) { int[] myArr1 = { 100, 150, 230, 300, 400 }; int[] myArr2 = { 450, 550, 700, 800, ... Read More
130 Views
The concat() function in Ints class is used to concatenate the arrays passed as parameter. The syntax is as follows −public static int[] concat(int[]... arr)Here, parameter arr is zero or more integer arrays.Let us see an example −Exampleimport com.google.common.primitives.Ints; import java.util.*; class Demo { public static void main(String[] args) { int[] myArr1 = { 100, 150, 230, 300, 400 }; int[] myArr2 = { 450, 550, 700, 800, 1000 }; System.out.println("Array 1 = "); for(int i=0; i < myArr1.length; i++) { System.out.println(myArr1[i]); ... Read More
164 Views
The asList() method of the Ints class in Java Guava’s returns a fixed-size list backed by the specified array. The syntax is as follows −public static List asList(int[] arr)Here, arr is the array to back the list.Let us see an example to implement the asList() method of the Ints class −Exampleimport com.google.common.primitives.Ints; import java.util.List; class Demo { public static void main(String[] args) { int arr[] = { 20, 30, 40, 60, 80, 90, 120, 150 }; System.out.println("Array elements = "); for(int i = 0; i < arr.length; i++) { ... Read More
108 Views
The java.lang.Integer.toHexString() method returns a string representation of the integer argument as an unsigned integer in base 16.Let us now see an example −Exampleimport java.lang.*; public class Main { public static void main(String[] args) { int i = 160; System.out.println("Number = " + i); System.out.println("Hex = " + Integer.toHexString(i)); } }OutputNumber = 160 Hex = a0ExampleLet us now see another example for negative number −import java.lang.*; public class Main { public static void main(String[] args) { int i = -160; System.out.println("Number = " + i); System.out.println("Hex = " + Integer.toHexString(i)); } }OutputNumber = -160 Hex = ffffff60
116 Views
The java.lang.Math.signum(float f) returns the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, -1.0f if the argument is less than zero.Let us now see an example −Exampleimport java.security.*; import java.util.*; public class Main { public static void main(String[] argv) { // get two float numbers float x = 50.14f; float y = -4f; // call signum for both floats and print the result System.out.println("Math.signum(" + x + ")=" + Math.signum(x)); ... Read More
89 Views
The string representation for the signature object can be obtained using the method getString() in the class java.security.Signature. This includes information such as the object state, algorithm name etcLet us now see an example −Exampleimport java.security.*; import java.util.*; public class Main { public static void main(String[] argv) { try { Signature signature = Signature.getInstance("SHA256withRSA"); String str = signature.toString(); System.out.println(str); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); } } }OutputSignature object: SHA256withRSALet us now ... Read More
297 Views
The initSign() method initialize this object for signing. If this method is called again with a different argument, it negates the effect of this call.Let us now see an example −Exampleimport java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.PrivateKey; import java.security.Signature; import java.util.Scanner; public class Main { public static void main(String args[]) throws Exception { //Creating KeyPair generator object KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("DSA"); //Initializing the key pair generator keyPairGen.initialize(2048); //Generate the pair of keys KeyPair pair = keyPairGen.generateKeyPair(); //Getting the privatekey ... Read More
104 Views
The provider for the signature object can be obtained using the method getProvider() in the class java.security.Signature.Let us now see an example −Exampleimport java.security.*; import java.util.*; public class Main { public static void main(String[] argv) { try { Signature signature = Signature.getInstance("SHA256withRSA"); Provider provider = signature.getProvider(); System.out.println("The Provider is: " + provider); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); } } }OutputThe Provider is: SunRsaSign version 11ExampleLet us now see another example −import ... Read More
238 Views
A class which contains the abstract keyword in its declaration is known as abstract class. Abstract classes may or may not contain abstract methods, i.e., methods without body. But, if a class has at least one abstract method, then the class must be declared abstract.If a class is declared abstract, it cannot be instantiated. To use an abstract class, you have to inherit it from another class, provide implementations to the abstract methods in it. If you inherit an abstract class, you have to provide implementations to all the abstract methods in it.Let us see a simple example −Exampleabstract class CricketLeague { abstract void ... Read More
617 Views
HashSet extends AbstractSet and implements the Set interface. It creates a collection that uses a hash table for storage.A hash table stores information by using a mechanism called hashing. In hashing, the informational content of a key is used to determine a unique value, called its hash code.To traverse through a HashSet, you can use the Iterator in Java. At first, create a HashSet with string values −HashSet hashSet = new HashSet(); hashSet.add("Jack"); hashSet.add("Tom"); hashSet.add("David"); hashSet.add("John"); hashSet.add("Steve");Now, traverse using Iterator −Iterator iterator = hashSet.iterator(); while(iterator.hasNext()){ System.out.println(iterator.next()); }Let us see a simple example wherein we have some HashSet elements and we ... Read More