Pages

Wednesday, October 29, 2025

Self-practice-01: Check if arrays are matching or not in Java

 import java.util.*;


public class Main

{

    

    

    public static void ifMatch(int[] arr) {

        

        // Combine array with a predefined array

        int[] pattern = {4, 3, 2, 6};

        

        // Check if arrays have same length

        if(Arrays.equals(arr, pattern)) {

            System.out.println("Yes, Array is matching.");

        } else {

            System.out.println("No, Array isn't matching.");

        }

    }

    

    

    

public static void main(String[] args) {

int[] testArr = {4, 3, 2, 6};

System.out.print("Array 1: ");

ifMatch(testArr);

int[] testArr2 = {4, 3, 2, 9};

System.out.print("Array 2: ");

ifMatch(testArr2);

}

}

No comments:

Post a Comment

3Sum - Leetcode solution - How i turned into two-pointer approach?

  class Solution {     public List < List < Integer >> threeSum ( int [] nums ) {         Arrays . sort (nums); // first sort...