Home » arrays

Tag Archives: arrays

ArrayList to Array Java Example

In this tutorial, we will look at various ways to convert ArrayList to array java and we will discuss the efficient approach for it. 1. ArrayList to Array in Java The first step for our example is to create an ArrayList List numbers = new ArrayList(); final int endRange = 100000000; IntStream.range(0, endRange).forEach(value -> { numbers.add(value + 1); }); We ...

Read More »

Remove element from an Array Java Example

Hello readers, in this tutorial, we will learn two different ways to remove an element from an array.So lets talk about java array remove operation. You can watch the following video and learn how to use arrays in Java: Java Array Example How to use Arrays in Java – Video 1. Introduction In Java programming, Arrays represent an index-based object ...

Read More »

Java 8 Array to Stream Example

1. Introduction Official javadoc of java.util.stream.Stream states that it is “A sequence of elements supporting sequential and parallel aggregate operations”. And such every Stream is backed by a source which would provide the Stream with its “sequence of elements”. In Java, like most other programming languages, sequence of elements is generally provided via two constructs: (i) the java.util.Collection instances and ...

Read More »

Groovy Array Example

Table Of Contents 1. Introduction 2. Array Declaration 3. Access Array Items 4. Add Item Exception 5. Array Length 6. Array Min & Max Value 7. Remove Item 8. Array Ordering 9. Array Lookup 10. Conversion 11. Conclusion 1. Introduction In previous tutorials, we have mentioned about Groovy List and provided lots of examples. In this tutorial, I will show ...

Read More »

java.lang.reflect.Array Example

In this example we shall explain how to use java.lang.reflect.Array. The java.lang.reflect.Array class provides static methods to dynamically create and access Java arrays. Arrays are objects that contain values of the same type, with immutable length. So, an array’s components of the same type and their number is always fixed. The length of an array must be set when an ...

Read More »

java.io.FileInputStream – Java FileInputStream Example

In this example, we are going to see how to use FileInputStream in Java and inputstream. FileInputStream in an InputStream subclass that is used to read data from files in a file system. It is actually connected to a specific file and can be used to extract data from them and make them available inside your program for manipulation. As ...

Read More »

Compare two dimensional arrays

With this example we are going to demonstrate how to compare two dimensional arrays. We are using int arrays, but the same API applies to any types of arrays, e.g. boolean[][], byte[][], char[][], double[][], float[][], long[][], short[][] and String[][]. In short, to compare two dimensional arrays we have implemented a method as described below: The example’s method is boolean equal(final ...

Read More »

Sort arrays example

This is an example of how to sort arrays. We are using an int array in the example, but the same API applies to any type of arrays e.g. byte[], char[], double[], float[], long[], short[]. Sorting an int array implies that you should: Create an int array with elements. Invoke sort(int[] a) API method of Arrays . It sorts an ...

Read More »

Binary search Java array example

In this example we shall show you how to search an element of an array using the binary algorithm in Java. We are using an int array in the example, but the same API applies to any type of arrays e.g. byte[], char[], double[], float[], long[], short[]. We are using the binarySearch(int[] b, int value) API method of Arrays. To ...

Read More »

Convert Object Array to List example

With this example we are going to demonstrate how to convert an Object array to a List. We are using a String array in the example. In short, to convert an String array to a List you should: Create a String array with elements. Invoke asList(Object[] objArray) API method of Arrays, with the list as parameter. It returns a fixed ...

Read More »