Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Object Oriented Programming Articles
Page 505 of 589
Calendar Functions in Java
The java.util.calendar class provides the calendar functions in Java. Is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for manipulating the calendar fields, such as getting the date of the next week.Following are the calendar functions in Java −Sr.NoMethod & Description1abstract void add(int field, int amount)This method adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules.2boolean after(Object when)This method returns whether this Calendar represents a time after the time ...
Read MoreInts toArray() function in Java
The toArray() method of the Ints class returns an array containing each value of collection, converted to a int value in the manner of Number.intValue(). Following is the syntax −public static int[] toArray(Collection
Read MoreInts max() function in Java
The max() method of the Ints class returns the greatest value present in array. Following is the syntax −static int max(int... array)Let us first see an example −Exampleimport com.google.common.primitives.Ints; class Demo { public static void main(String[] args) { int[] myArr = { 10, 20, 30, 40, 50, 60, 20, 80, 20, 100 }; System.out.println(Ints.join("-", myArr)); System.out.println("Maximum value from the array = " + Ints.max(myArr)); // finding last index of element 20 int index = Ints.lastIndexOf(myArr, 20); if (index != -1) { ...
Read MoreDivision Operators in Java
The division operator in Java includes the Division, Modulus, and the Divide And Assignment operator. Let us work with them one by one −Divison OperatorThe division operator divides left-hand operand by right-hand operand.Modulus OperatorThe modulus operator divides left-hand operand by right-hand operand and returns remainder.Divide And Assignment OperatorThis operator divides left operand with the right operand and assign the result to left operand.Let us now see an example −Examplepublic class Demo { public static void main( String args[] ) { int a = 10; int b = 20; int c ...
Read MoreInts join() function in Java
The join() method of Ints class returns a string containing the supplied int values separated by separator. The syntax is as follows −public static String join(String separator, int[] arr)Here, separator parameter is something that should appear between consecutive values, whereas arr is an array of int values.Let us first see an example −Exampleimport com.google.common.primitives.Ints; class Demo { public static void main(String[] args) { int[] myArr = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }; System.out.println(Ints.join("-", myArr)); int index = Ints.indexOf(myArr, 40); if ...
Read MoreInts indexOf() function in Java
The indexOf() method of the Ints class returns the index of the first appearance of the value target in array. The syntax is as follows −public static int indexOf(int[] arr, int target)Here, parameter arr is an array of int values and target is the value to be checked for first appearance.Let us now see an example −Exampleimport com.google.common.primitives.Ints; class Demo { public static void main(String[] args) { int[] arr = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }; int index = Ints.indexOf(arr, 40); if (index != ...
Read MoreProgram to convert Set to List in Java
Let’s say the following is our Set with string values −Set set = new HashSet(); set.add("Laptop"); set.add("Mobile"); set.add("Tablet"); set.add("LCD"); set.add("LED");Now, let us convert it to List −List list = new ArrayList(set);Following is the program to convert Set to List in Java −Exampleimport java.util.*; import java.util.stream.*; public class Demo { public static void main(String args[]) { Set set = new HashSet(); set.add("Laptop"); set.add("Mobile"); set.add("Tablet"); set.add("LCD"); set.add("LED"); set.add("Desktop"); System.out.println("Set = " + set); List ...
Read MoreProgram to convert set of String to set of Integer in Java
Let’s say the following is our set of string −Set setStr = new HashSet(Arrays.asList("50", "100", "150", "200", "250", "300", "500"));Now, convert it to set of Integer −Set setInteger = setStr.stream().map(s -> Integer.parseInt(s)).collect(Collectors.toSet());ExampleFollowing is the program to convert set of String to set of Integer in Java −import java.util.*; import java.util.stream.*; public class Demo { public static void main(String args[]) { Set setStr = new HashSet(Arrays.asList("50", "100", "150", "200", "250", "300", "500")); System.out.println("Set (String) = " + setStr); Set setInteger = setStr.stream().map(s -> Integer.parseInt(s)) .collect(Collectors.toSet()); ...
Read MoreProgram to convert Set of Integer to Set of String in Java
Let’s say the following is our Set of Integer −Set setInteger = new HashSet(Arrays.asList(100, 200, 300, 500, 600, 800, 1000));Now, let us convert this to Set of String −Set setStr = setInteger.stream().map(String::valueOf).collect(Collectors.toSet());ExampleFollowing is the program to convert set of Integer to Set of String in Java −import java.util.*; import java.util.stream.*; import java.util.function.Function; public class Demo { public static void main(String args[]) { Set setInteger = new HashSet(Arrays.asList(100, 200, 300, 500, 600, 800, 1000)); System.out.println("Set = " + setInteger); Set setStr = setInteger.stream().map(String::valueOf).collect(Collectors.toSet()); System.out.println("New Set (String) = " ...
Read MoreProgram to convert set of Integer to Array of Integer in Java
Let’s say the following is our set of Integer −Set set = new HashSet(Arrays.asList(50, 100, 150, 200, 400, 600, 800, 1000, 1200, 1500));Now, convert it to Array of Integer −int[] arr = set.stream() .mapToInt(Integer::intValue) .toArray();ExampleFollowing is the program to convert set of Integer to Array of Integer in Java −import java.util.*; import java.util.stream.*; import java.util.function.Function; public class Demo { public static void main(String args[]) { Set set = new HashSet(Arrays.asList(50, 100, 150, 200, 400, 600, 800, 1000, 1200, 1500)); System.out.println("Set = " + set); int[] arr = set.stream().mapToInt(Integer::intValue).toArray(); System.out.println("Array = "+ Arrays.toString(arr)); } }OutputSet = [400, 800, 1200, 50, 100, 150, 200, 600, 1000, 1500] Array = [400, 800, 1200, 50, 100, 150, 200, 600, 1000, 1500]
Read More