find repeated values in an array and print them to list view in android












0















I am new in android and I am trying to get the duplicate values in an array list. I have searched over the internet but I got nothing.



My project has two array lists one is for numbers and the second one is for displaying them. And if the first array list contains a duplicate values, the second one will display all the values and the duplicate ones will be displayed with a stars to mark them as a duplicate values.
So I have tried the following code but I have got nothing. In this situation, array list contains [9,9,5,7].
The problem is I do not get what I need, here is my code.
Note that: arrayList object that contains the numbers, array object will display them.. So any help on this?



arrayList.add(Integer.valueOf(students.getSeatnum()));
array.add(students.getStuden_name() + ", Student " + students.getStudent_id() + ", Seat Num: " + students.getSeatnum());

Set<Integer> seenValues = new HashSet();

for(Integer value: arrayList) {
if(seenValues.contains(value)) {
array.add(students.getStuden_name() + ", Student " + students. getStudent_id() + ", Seat Num: " + students.getSeatnum()+ "****");
adapter = new ArrayAdapter<String>(StudentInfo.this, android.R.layout.simple_list_item_1, array);
listView.setAdapter(adapter);
} else {
adapter = new ArrayAdapter<String>(StudentInfo.this, android.R.layout.simple_list_item_1, array);
listView.setAdapter(adapter);
}
}









share|improve this question





























    0















    I am new in android and I am trying to get the duplicate values in an array list. I have searched over the internet but I got nothing.



    My project has two array lists one is for numbers and the second one is for displaying them. And if the first array list contains a duplicate values, the second one will display all the values and the duplicate ones will be displayed with a stars to mark them as a duplicate values.
    So I have tried the following code but I have got nothing. In this situation, array list contains [9,9,5,7].
    The problem is I do not get what I need, here is my code.
    Note that: arrayList object that contains the numbers, array object will display them.. So any help on this?



    arrayList.add(Integer.valueOf(students.getSeatnum()));
    array.add(students.getStuden_name() + ", Student " + students.getStudent_id() + ", Seat Num: " + students.getSeatnum());

    Set<Integer> seenValues = new HashSet();

    for(Integer value: arrayList) {
    if(seenValues.contains(value)) {
    array.add(students.getStuden_name() + ", Student " + students. getStudent_id() + ", Seat Num: " + students.getSeatnum()+ "****");
    adapter = new ArrayAdapter<String>(StudentInfo.this, android.R.layout.simple_list_item_1, array);
    listView.setAdapter(adapter);
    } else {
    adapter = new ArrayAdapter<String>(StudentInfo.this, android.R.layout.simple_list_item_1, array);
    listView.setAdapter(adapter);
    }
    }









    share|improve this question



























      0












      0








      0








      I am new in android and I am trying to get the duplicate values in an array list. I have searched over the internet but I got nothing.



      My project has two array lists one is for numbers and the second one is for displaying them. And if the first array list contains a duplicate values, the second one will display all the values and the duplicate ones will be displayed with a stars to mark them as a duplicate values.
      So I have tried the following code but I have got nothing. In this situation, array list contains [9,9,5,7].
      The problem is I do not get what I need, here is my code.
      Note that: arrayList object that contains the numbers, array object will display them.. So any help on this?



      arrayList.add(Integer.valueOf(students.getSeatnum()));
      array.add(students.getStuden_name() + ", Student " + students.getStudent_id() + ", Seat Num: " + students.getSeatnum());

      Set<Integer> seenValues = new HashSet();

      for(Integer value: arrayList) {
      if(seenValues.contains(value)) {
      array.add(students.getStuden_name() + ", Student " + students. getStudent_id() + ", Seat Num: " + students.getSeatnum()+ "****");
      adapter = new ArrayAdapter<String>(StudentInfo.this, android.R.layout.simple_list_item_1, array);
      listView.setAdapter(adapter);
      } else {
      adapter = new ArrayAdapter<String>(StudentInfo.this, android.R.layout.simple_list_item_1, array);
      listView.setAdapter(adapter);
      }
      }









      share|improve this question
















      I am new in android and I am trying to get the duplicate values in an array list. I have searched over the internet but I got nothing.



      My project has two array lists one is for numbers and the second one is for displaying them. And if the first array list contains a duplicate values, the second one will display all the values and the duplicate ones will be displayed with a stars to mark them as a duplicate values.
      So I have tried the following code but I have got nothing. In this situation, array list contains [9,9,5,7].
      The problem is I do not get what I need, here is my code.
      Note that: arrayList object that contains the numbers, array object will display them.. So any help on this?



      arrayList.add(Integer.valueOf(students.getSeatnum()));
      array.add(students.getStuden_name() + ", Student " + students.getStudent_id() + ", Seat Num: " + students.getSeatnum());

      Set<Integer> seenValues = new HashSet();

      for(Integer value: arrayList) {
      if(seenValues.contains(value)) {
      array.add(students.getStuden_name() + ", Student " + students. getStudent_id() + ", Seat Num: " + students.getSeatnum()+ "****");
      adapter = new ArrayAdapter<String>(StudentInfo.this, android.R.layout.simple_list_item_1, array);
      listView.setAdapter(adapter);
      } else {
      adapter = new ArrayAdapter<String>(StudentInfo.this, android.R.layout.simple_list_item_1, array);
      listView.setAdapter(adapter);
      }
      }






      android arraylist






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 at 19:45









      mariusd96

      955




      955










      asked Jan 2 at 15:31









      SawsanSawsan

      125




      125
























          2 Answers
          2






          active

          oldest

          votes


















          1














          Create an Adapter which accepts arrayList you have created.
          Assuming you are using ListView from your variable name convention.



          public class MySimpleArrayAdapter extends ArrayAdapter<String> {
          private final Context context;
          private final List<String> values;

          public MySimpleArrayAdapter(Context context, List<String> values) {
          super(context, -1, values);
          this.context = context;
          this.values = values;
          }

          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
          LayoutInflater inflater = (LayoutInflater) context. getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
          TextView textView = (TextView) rowView.findViewById(R.id.label);
          textView.setText(values.get(position));

          return rowView;
          }
          }


          Your method will look like this



          ArrayList<String> array =  new ArrayList<>();
          Map<Integer,Integer> seenValues = new HashMap<>();
          int i=0;
          for(int value : arrayList){
          if(seenValues.containsKey(value)){
          if(seenValues.get(value) !=-1){
          array.set(seenValues.get(value), String.valueOf(value) + "*");
          seenValues.put(value,-1);
          }
          array.add(String.valueOf(value)+"*");
          }else{
          array.add(String.valueOf(value));
          seenValues.put(value,i);
          }
          i++;
          }

          MySimpleArrayAdapter adapter = new adapter(context,array);
          setListAdapter(adapter);





          share|improve this answer


























          • it returned every element in array list 4 times!!!!! :(

            – Sawsan
            Jan 2 at 17:21











          • Let me clearly understand what you need.. [9,9,9,7,4,3,3] ----> [9*,7,4,3*] or [9,9,9,7,4,3,3] ----> [9*,3*]

            – vinay kant
            Jan 2 at 18:02













          • The above code will work @Sawsan. I have edited it for your use case.

            – vinay kant
            Jan 2 at 18:08













          • What i need is: [9,9,9,7,4,3,3] ------> [9*,9*,9*,7,4,3*,3*]. So I tried your suggestion but it gives me an error, tried to solve it but no results occur java.lang.IndexOutOfBoundsException: Index: 9, Size: 0 in line seenValues.add(value, array.size()-1);

            – Sawsan
            Jan 2 at 18:41











          • sorry for so many edits, but this edit will definitely work as per your requirements and it is O(n) solution. @Sawsan

            – vinay kant
            Jan 3 at 4:08



















          0














          You can do it this way:



          public class Test {
          List<Integer> digits ;
          List<String> digitsWatch;
          public Test() {
          digits = Arrays.asList(9,9,9,5,7,3,3);
          digitsWatch = new ArrayList<>(digits.size());

          // copying your array
          for (int i = 0; i < digits.size(); i++) {
          digitsWatch.add(digits.get(i).toString());
          }

          //filtred values
          boolean hasDublicaqtes = false;
          for (int i = 0; i < digits.size() -1 ; i++) {
          for (int j = i +1; j < digits.size() ; j++) {
          if(digitsWatch.get(j).equals(digits.get(i).toString()) ) {
          hasDublicaqtes = true;
          String tmp = digitsWatch.get(i) + "*";
          digitsWatch.set(j,tmp);
          }
          }
          if(hasDublicaqtes) {
          String tmp = digitsWatch.get(i) + "*";
          digitsWatch.set(i,tmp);
          }
          hasDublicaqtes = false;
          }
          }
          }


          Maybe it's not an optimal way but it works!






          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009027%2ffind-repeated-values-in-an-array-and-print-them-to-list-view-in-android%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Create an Adapter which accepts arrayList you have created.
            Assuming you are using ListView from your variable name convention.



            public class MySimpleArrayAdapter extends ArrayAdapter<String> {
            private final Context context;
            private final List<String> values;

            public MySimpleArrayAdapter(Context context, List<String> values) {
            super(context, -1, values);
            this.context = context;
            this.values = values;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) context. getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
            TextView textView = (TextView) rowView.findViewById(R.id.label);
            textView.setText(values.get(position));

            return rowView;
            }
            }


            Your method will look like this



            ArrayList<String> array =  new ArrayList<>();
            Map<Integer,Integer> seenValues = new HashMap<>();
            int i=0;
            for(int value : arrayList){
            if(seenValues.containsKey(value)){
            if(seenValues.get(value) !=-1){
            array.set(seenValues.get(value), String.valueOf(value) + "*");
            seenValues.put(value,-1);
            }
            array.add(String.valueOf(value)+"*");
            }else{
            array.add(String.valueOf(value));
            seenValues.put(value,i);
            }
            i++;
            }

            MySimpleArrayAdapter adapter = new adapter(context,array);
            setListAdapter(adapter);





            share|improve this answer


























            • it returned every element in array list 4 times!!!!! :(

              – Sawsan
              Jan 2 at 17:21











            • Let me clearly understand what you need.. [9,9,9,7,4,3,3] ----> [9*,7,4,3*] or [9,9,9,7,4,3,3] ----> [9*,3*]

              – vinay kant
              Jan 2 at 18:02













            • The above code will work @Sawsan. I have edited it for your use case.

              – vinay kant
              Jan 2 at 18:08













            • What i need is: [9,9,9,7,4,3,3] ------> [9*,9*,9*,7,4,3*,3*]. So I tried your suggestion but it gives me an error, tried to solve it but no results occur java.lang.IndexOutOfBoundsException: Index: 9, Size: 0 in line seenValues.add(value, array.size()-1);

              – Sawsan
              Jan 2 at 18:41











            • sorry for so many edits, but this edit will definitely work as per your requirements and it is O(n) solution. @Sawsan

              – vinay kant
              Jan 3 at 4:08
















            1














            Create an Adapter which accepts arrayList you have created.
            Assuming you are using ListView from your variable name convention.



            public class MySimpleArrayAdapter extends ArrayAdapter<String> {
            private final Context context;
            private final List<String> values;

            public MySimpleArrayAdapter(Context context, List<String> values) {
            super(context, -1, values);
            this.context = context;
            this.values = values;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) context. getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
            TextView textView = (TextView) rowView.findViewById(R.id.label);
            textView.setText(values.get(position));

            return rowView;
            }
            }


            Your method will look like this



            ArrayList<String> array =  new ArrayList<>();
            Map<Integer,Integer> seenValues = new HashMap<>();
            int i=0;
            for(int value : arrayList){
            if(seenValues.containsKey(value)){
            if(seenValues.get(value) !=-1){
            array.set(seenValues.get(value), String.valueOf(value) + "*");
            seenValues.put(value,-1);
            }
            array.add(String.valueOf(value)+"*");
            }else{
            array.add(String.valueOf(value));
            seenValues.put(value,i);
            }
            i++;
            }

            MySimpleArrayAdapter adapter = new adapter(context,array);
            setListAdapter(adapter);





            share|improve this answer


























            • it returned every element in array list 4 times!!!!! :(

              – Sawsan
              Jan 2 at 17:21











            • Let me clearly understand what you need.. [9,9,9,7,4,3,3] ----> [9*,7,4,3*] or [9,9,9,7,4,3,3] ----> [9*,3*]

              – vinay kant
              Jan 2 at 18:02













            • The above code will work @Sawsan. I have edited it for your use case.

              – vinay kant
              Jan 2 at 18:08













            • What i need is: [9,9,9,7,4,3,3] ------> [9*,9*,9*,7,4,3*,3*]. So I tried your suggestion but it gives me an error, tried to solve it but no results occur java.lang.IndexOutOfBoundsException: Index: 9, Size: 0 in line seenValues.add(value, array.size()-1);

              – Sawsan
              Jan 2 at 18:41











            • sorry for so many edits, but this edit will definitely work as per your requirements and it is O(n) solution. @Sawsan

              – vinay kant
              Jan 3 at 4:08














            1












            1








            1







            Create an Adapter which accepts arrayList you have created.
            Assuming you are using ListView from your variable name convention.



            public class MySimpleArrayAdapter extends ArrayAdapter<String> {
            private final Context context;
            private final List<String> values;

            public MySimpleArrayAdapter(Context context, List<String> values) {
            super(context, -1, values);
            this.context = context;
            this.values = values;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) context. getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
            TextView textView = (TextView) rowView.findViewById(R.id.label);
            textView.setText(values.get(position));

            return rowView;
            }
            }


            Your method will look like this



            ArrayList<String> array =  new ArrayList<>();
            Map<Integer,Integer> seenValues = new HashMap<>();
            int i=0;
            for(int value : arrayList){
            if(seenValues.containsKey(value)){
            if(seenValues.get(value) !=-1){
            array.set(seenValues.get(value), String.valueOf(value) + "*");
            seenValues.put(value,-1);
            }
            array.add(String.valueOf(value)+"*");
            }else{
            array.add(String.valueOf(value));
            seenValues.put(value,i);
            }
            i++;
            }

            MySimpleArrayAdapter adapter = new adapter(context,array);
            setListAdapter(adapter);





            share|improve this answer















            Create an Adapter which accepts arrayList you have created.
            Assuming you are using ListView from your variable name convention.



            public class MySimpleArrayAdapter extends ArrayAdapter<String> {
            private final Context context;
            private final List<String> values;

            public MySimpleArrayAdapter(Context context, List<String> values) {
            super(context, -1, values);
            this.context = context;
            this.values = values;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) context. getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
            TextView textView = (TextView) rowView.findViewById(R.id.label);
            textView.setText(values.get(position));

            return rowView;
            }
            }


            Your method will look like this



            ArrayList<String> array =  new ArrayList<>();
            Map<Integer,Integer> seenValues = new HashMap<>();
            int i=0;
            for(int value : arrayList){
            if(seenValues.containsKey(value)){
            if(seenValues.get(value) !=-1){
            array.set(seenValues.get(value), String.valueOf(value) + "*");
            seenValues.put(value,-1);
            }
            array.add(String.valueOf(value)+"*");
            }else{
            array.add(String.valueOf(value));
            seenValues.put(value,i);
            }
            i++;
            }

            MySimpleArrayAdapter adapter = new adapter(context,array);
            setListAdapter(adapter);






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 3 at 4:07

























            answered Jan 2 at 16:40









            vinay kantvinay kant

            564




            564













            • it returned every element in array list 4 times!!!!! :(

              – Sawsan
              Jan 2 at 17:21











            • Let me clearly understand what you need.. [9,9,9,7,4,3,3] ----> [9*,7,4,3*] or [9,9,9,7,4,3,3] ----> [9*,3*]

              – vinay kant
              Jan 2 at 18:02













            • The above code will work @Sawsan. I have edited it for your use case.

              – vinay kant
              Jan 2 at 18:08













            • What i need is: [9,9,9,7,4,3,3] ------> [9*,9*,9*,7,4,3*,3*]. So I tried your suggestion but it gives me an error, tried to solve it but no results occur java.lang.IndexOutOfBoundsException: Index: 9, Size: 0 in line seenValues.add(value, array.size()-1);

              – Sawsan
              Jan 2 at 18:41











            • sorry for so many edits, but this edit will definitely work as per your requirements and it is O(n) solution. @Sawsan

              – vinay kant
              Jan 3 at 4:08



















            • it returned every element in array list 4 times!!!!! :(

              – Sawsan
              Jan 2 at 17:21











            • Let me clearly understand what you need.. [9,9,9,7,4,3,3] ----> [9*,7,4,3*] or [9,9,9,7,4,3,3] ----> [9*,3*]

              – vinay kant
              Jan 2 at 18:02













            • The above code will work @Sawsan. I have edited it for your use case.

              – vinay kant
              Jan 2 at 18:08













            • What i need is: [9,9,9,7,4,3,3] ------> [9*,9*,9*,7,4,3*,3*]. So I tried your suggestion but it gives me an error, tried to solve it but no results occur java.lang.IndexOutOfBoundsException: Index: 9, Size: 0 in line seenValues.add(value, array.size()-1);

              – Sawsan
              Jan 2 at 18:41











            • sorry for so many edits, but this edit will definitely work as per your requirements and it is O(n) solution. @Sawsan

              – vinay kant
              Jan 3 at 4:08

















            it returned every element in array list 4 times!!!!! :(

            – Sawsan
            Jan 2 at 17:21





            it returned every element in array list 4 times!!!!! :(

            – Sawsan
            Jan 2 at 17:21













            Let me clearly understand what you need.. [9,9,9,7,4,3,3] ----> [9*,7,4,3*] or [9,9,9,7,4,3,3] ----> [9*,3*]

            – vinay kant
            Jan 2 at 18:02







            Let me clearly understand what you need.. [9,9,9,7,4,3,3] ----> [9*,7,4,3*] or [9,9,9,7,4,3,3] ----> [9*,3*]

            – vinay kant
            Jan 2 at 18:02















            The above code will work @Sawsan. I have edited it for your use case.

            – vinay kant
            Jan 2 at 18:08







            The above code will work @Sawsan. I have edited it for your use case.

            – vinay kant
            Jan 2 at 18:08















            What i need is: [9,9,9,7,4,3,3] ------> [9*,9*,9*,7,4,3*,3*]. So I tried your suggestion but it gives me an error, tried to solve it but no results occur java.lang.IndexOutOfBoundsException: Index: 9, Size: 0 in line seenValues.add(value, array.size()-1);

            – Sawsan
            Jan 2 at 18:41





            What i need is: [9,9,9,7,4,3,3] ------> [9*,9*,9*,7,4,3*,3*]. So I tried your suggestion but it gives me an error, tried to solve it but no results occur java.lang.IndexOutOfBoundsException: Index: 9, Size: 0 in line seenValues.add(value, array.size()-1);

            – Sawsan
            Jan 2 at 18:41













            sorry for so many edits, but this edit will definitely work as per your requirements and it is O(n) solution. @Sawsan

            – vinay kant
            Jan 3 at 4:08





            sorry for so many edits, but this edit will definitely work as per your requirements and it is O(n) solution. @Sawsan

            – vinay kant
            Jan 3 at 4:08













            0














            You can do it this way:



            public class Test {
            List<Integer> digits ;
            List<String> digitsWatch;
            public Test() {
            digits = Arrays.asList(9,9,9,5,7,3,3);
            digitsWatch = new ArrayList<>(digits.size());

            // copying your array
            for (int i = 0; i < digits.size(); i++) {
            digitsWatch.add(digits.get(i).toString());
            }

            //filtred values
            boolean hasDublicaqtes = false;
            for (int i = 0; i < digits.size() -1 ; i++) {
            for (int j = i +1; j < digits.size() ; j++) {
            if(digitsWatch.get(j).equals(digits.get(i).toString()) ) {
            hasDublicaqtes = true;
            String tmp = digitsWatch.get(i) + "*";
            digitsWatch.set(j,tmp);
            }
            }
            if(hasDublicaqtes) {
            String tmp = digitsWatch.get(i) + "*";
            digitsWatch.set(i,tmp);
            }
            hasDublicaqtes = false;
            }
            }
            }


            Maybe it's not an optimal way but it works!






            share|improve this answer






























              0














              You can do it this way:



              public class Test {
              List<Integer> digits ;
              List<String> digitsWatch;
              public Test() {
              digits = Arrays.asList(9,9,9,5,7,3,3);
              digitsWatch = new ArrayList<>(digits.size());

              // copying your array
              for (int i = 0; i < digits.size(); i++) {
              digitsWatch.add(digits.get(i).toString());
              }

              //filtred values
              boolean hasDublicaqtes = false;
              for (int i = 0; i < digits.size() -1 ; i++) {
              for (int j = i +1; j < digits.size() ; j++) {
              if(digitsWatch.get(j).equals(digits.get(i).toString()) ) {
              hasDublicaqtes = true;
              String tmp = digitsWatch.get(i) + "*";
              digitsWatch.set(j,tmp);
              }
              }
              if(hasDublicaqtes) {
              String tmp = digitsWatch.get(i) + "*";
              digitsWatch.set(i,tmp);
              }
              hasDublicaqtes = false;
              }
              }
              }


              Maybe it's not an optimal way but it works!






              share|improve this answer




























                0












                0








                0







                You can do it this way:



                public class Test {
                List<Integer> digits ;
                List<String> digitsWatch;
                public Test() {
                digits = Arrays.asList(9,9,9,5,7,3,3);
                digitsWatch = new ArrayList<>(digits.size());

                // copying your array
                for (int i = 0; i < digits.size(); i++) {
                digitsWatch.add(digits.get(i).toString());
                }

                //filtred values
                boolean hasDublicaqtes = false;
                for (int i = 0; i < digits.size() -1 ; i++) {
                for (int j = i +1; j < digits.size() ; j++) {
                if(digitsWatch.get(j).equals(digits.get(i).toString()) ) {
                hasDublicaqtes = true;
                String tmp = digitsWatch.get(i) + "*";
                digitsWatch.set(j,tmp);
                }
                }
                if(hasDublicaqtes) {
                String tmp = digitsWatch.get(i) + "*";
                digitsWatch.set(i,tmp);
                }
                hasDublicaqtes = false;
                }
                }
                }


                Maybe it's not an optimal way but it works!






                share|improve this answer















                You can do it this way:



                public class Test {
                List<Integer> digits ;
                List<String> digitsWatch;
                public Test() {
                digits = Arrays.asList(9,9,9,5,7,3,3);
                digitsWatch = new ArrayList<>(digits.size());

                // copying your array
                for (int i = 0; i < digits.size(); i++) {
                digitsWatch.add(digits.get(i).toString());
                }

                //filtred values
                boolean hasDublicaqtes = false;
                for (int i = 0; i < digits.size() -1 ; i++) {
                for (int j = i +1; j < digits.size() ; j++) {
                if(digitsWatch.get(j).equals(digits.get(i).toString()) ) {
                hasDublicaqtes = true;
                String tmp = digitsWatch.get(i) + "*";
                digitsWatch.set(j,tmp);
                }
                }
                if(hasDublicaqtes) {
                String tmp = digitsWatch.get(i) + "*";
                digitsWatch.set(i,tmp);
                }
                hasDublicaqtes = false;
                }
                }
                }


                Maybe it's not an optimal way but it works!







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 2 at 22:12

























                answered Jan 2 at 22:06









                Stanislav BaturaStanislav Batura

                220110




                220110






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009027%2ffind-repeated-values-in-an-array-and-print-them-to-list-view-in-android%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    Npm cannot find a required file even through it is in the searched directory

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith