package com.example.andy.myapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class MainActivity extends AppCompatActivity {
    ListView list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Set<String> set = new HashSet<>();
        ArrayList<String> MainListItem = new ArrayList<String>();
        MainListItem.add("Sai");
        MainListItem.add("Sai");
        MainListItem.add("ram");
        MainListItem.add("Sai krishna");
        MainListItem.add("Sai Ram Krishna");
        MainListItem.add("tutorialspoint.com");
        MainListItem.add("tutorialspoint.com");
        ArrayList<String> duplicates = new ArrayList<String>();
        for (String s : MainListItem) {
            if (!set.add(s)) {
                duplicates.add(s);
            }
        }
        list = findViewById(R.id.list);
        ArrayAdapter arrayAdapter = new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, duplicates);
        list.setAdapter(arrayAdapter);


    }
}
