Friday, May 9, 2014

How to sort and remove the duplicates from array without using sort() method.


import org.apache.commons.lang3.ArrayUtils;

public class SortAndRemoveDuplicate {
    public static void main(String[] args) {
        int[] a = {1,5,3,2,1,11,7,5};
        int l = a.length, s=0;       
        for(int j=0; j<l; j++){
            for(int i=0; i<l-1; i++){
                if(a[i]>a[i+1]){
                    s = a[i];
                    a[i] = a[i+1];
                    a[i+1] = s;
                }else if(a[i]==a[i+1]){
                    a = ArrayUtils.remove(a, i);
                    l = a.length;
                }
            }
        }
        for(int n: a){
            System.out.println(n);
        }
    }
}

12 comments:

  1. What are the advantages of pom frame work in selenium?????????

    ReplyDelete
  2. Main advantage-
    1- avoid to write the duplicate locators for same WebElement which is the big issue in other frameworks.
    2- Maintenance of the test script which becomes very easy.
    3- improves readability

    ReplyDelete
  3. What is annotations?How ll u configure in Framework????

    ReplyDelete
  4. plz help Sanjay Kumar...i need d answer.....

    ReplyDelete
  5. There are many annotations which has been provided in TestNG to make the scripting easy and code reusability.

    Here are the Annotations used in TestNG-
    @Test
    @BeforeSuite, @AfterSuite
    @BeforeTest, @AfterTest
    @BeforeClass, @AfterClass
    @BeforeMethod, @AfterMethod
    @DataProvider
    @Parameters.

    How to use-
    ex-
    @BeforeMethod
    public void openBrow(){
    WebDriver driver = new FirefoxDriver();
    System.out.println("open browser");
    }
    @Test
    public void atTest(){
    System.out.println("here 1st @BeforeMethod will execute then @Test");
    }

    ReplyDelete
  6. can u tell me how to do email validation using selenium web driver

    ReplyDelete
    Replies
    1. you can refer this.

      http://selenium-makeiteasy.blogspot.in/search/label/send%20mail%20thru%20gmail%20with%20attachment

      Delete
  7. why we create FirefoxProfile object when work with ssl pop-up handling????

    ReplyDelete
    Replies
    1. FirefoxProfile is used to change the default settings of the firefox browser which is going to open by webdriver.

      Delete
  8. what is the need of creation of firefoxprofile object?

    ReplyDelete
    Replies
    1. say if you want to save the file while downloading in a particular location or you don't want to pop-up that download popup so in this case you use FirefoxProfile.

      Delete