package com.qahumor; import java.util.Iterator; import java.util.TreeSet; /*@author : qahumor * Given two Unsorted Arrays a1 and a2, * Remove duplicates and merged both into sorted order * */ public class TwoUnsortedArrayMergedAndSorted { public static void main(String[] args) { int[] a1 = {1,2,3,49,6,77,8}; int[] a2 = {3,67,77,3,10,54}; int[] a3; TreeSet<Integer> ts = new TreeSet<Integer>(); for(int i = 0 ; i < a1.length;i++){ ts.add(a1[i]); } for(int j = 0 ; j < a2.length ; j++){ ts.add(a2[j]); } Iterator<Integer> it = ts.iterator(); a3 = new int[ts.size()]; int k =0; while(it.hasNext()){ a3[k] = it.next(); k++; } for(int p = 0 ; p < a3.length ; p++){ System.out.print(a3[p]+","); } } }
Explore the Latest in Tech & Automation: Android, iOS, Mobile Testing with Appium, Web Automation using Selenium, Python & Java Programming, Robot Framework, Shell & PowerShell Scripting, QA Tools, Spring Boot Development, Agentic AI Innovations, Free Software Resources, and Expert Tips on Designing Scalable Automation Frameworks.
Showing posts with label Java question. Show all posts
Showing posts with label Java question. Show all posts
Sunday, August 16, 2015
Java : Given two unsorted arrays ,write a program to remove duplicates and merge it into sorted order
Subscribe to:
Posts (Atom)
Linux: How to change OS language via terminal?
In this post , I will be talking about how to change language of Linux OS from Terminal . If you are not a frequent user of Linux and str...
-
How to change language of device using commandLine Changing language in Android device on-the fly is needed when we are running or exe...
-
How to find the UDID of Android Device What is UDID : It stands for Unique Device Identifier. UDID is required duri...
-
How to get the package name of Android application There are multiple ways in which we can obtain the package name of Android .apk file. ...