Array Examples: Part 4
This lesson discusses more challenging examples of arrays to enhance your knowledge and understanding.
We'll cover the following...
Coding example: 41
As we have said earlier, Java has many built-in array methods that can help us manipulate an array according to our requirements.
Press + to interact
import java.util.Arrays;/*We can check if any array has a certain value*/public class ExampleFortyOne {public static void main(String[] args){//array declarationint[] myNumber = new int[3];//now we need to add elementsmyNumber[0] = 50;myNumber[1] = 60;myNumber[2] = 70;//etcint[] anotherNumber = {1, 2, 3};String[] nameColection = {"John", "Bob", "Mary"};System.out.println("Does array nameCollection contains this element? "+ Arrays.asList(nameColection).contains(2));System.out.println("Does array nameCollection contains this element? "+ Arrays.asList(nameColection).contains("John"));}}
Code explanation
In the first case, we have passed a numerical value. As expected, the answer will be false
. Because the array was of the String
type, the next one is ...
Access this course and 1400+ top-rated courses and projects.