CORE API / NOTES</>↗Core API07 Apr 2006
In this example we are going to learn how to sort an array of objects. We start by using an array of String objects as can be seen in the code snippet below. We sort the contents of the array using Arrays.sort() method and print the sorted result. It was really simple. String names[] = […]
CORE API / NOTES</>↗Core API04 Apr 2006
package org.kodejava.util; import java.util.Arrays; public class ArraySearchExample { public static void main(String[] args) { // We create an array of ints where the search will be done. int[] items = {9, 5, 14, 6, 11, 28, 9, 16, 37, 3, 2}; // The Arrays.binarySearch() require us to sort the array // items before we call […]
CORE API / NOTES</>↗Core API02 Apr 2006
package org.kodejava.util; import java.util.Arrays; public class ArraySortExample { public static void main(String[] args) { // An array of random numbers int[] numbers = {3, 1, 8, 34, 1, 2, 13, 89, 5, 21, 55}; System.out.println("Before: " + Arrays.toString(numbers)); // We need to sort these array elements into a correct order // from the smallest to […]
APACHE COMMONS / NOTES</>↗Apache Commons01 Apr 2006
To convert from primitive arrays into object type arrays, we can use the Apache Commons Lang library. The Commons Lang provides an ArrayUtils class that does this conversion. To convert the other way just use the toPrimitive() method. package org.kodejava.commons.lang; import org.apache.commons.lang3.ArrayUtils; public class ArrayPrimitiveObjectConversionDemo { public static void main(String[] args) { int[] numbers = […]
CORE API / NOTES</>↗Core API28 Mar 2006
To check if a file, or a directory exists we can utilize java.io.File.exists() method. This method return either true or false. Before we can check whether its exists or not we need to create an instance of File that represent an abstract path name of the file or directory. After we have the File instance […]
CORE API / NOTES</>↗Core API23 Mar 2006
In the code snippet below we are going to learn how to use the System.arraycopy() method to copy array values. This method will copy array from the specified source array, starting from the element specified by starting position. The array values will be copied to the target array, placed at the specified start position in […]