Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>public class TestDuplicate { /** * @param args */ static List&lt;String&gt; list = new ArrayList&lt;String&gt;(0); private static String[] skipElements; public static void main(String[] args) { list.add("Test"); list.add("xyz"); list.add("xyz"); list.add("pqrs"); list.add("pqrs"); list.add("abcd"); skipElements = new String[list.size()]; for(int i = 0; i &lt; list.size() ; i++){ if(isDuplicate(list.get(i), i)){ skipElements[i] = list.get(i); } } removeAllDuplicate(); System.out.println("Non Duplicates are--&gt;"+ list); } private static boolean isDuplicate(String element, int index){ for(int i = index+1; i &lt; list.size(); i++){ if(checkExistance(element) ){ return Boolean.TRUE; }else{ if(element.equalsIgnoreCase(list.get(i))){ return Boolean.TRUE; } } } return false; } private static boolean checkExistance(String element){ for(int i = 0 ; i &lt; skipElements.length ; i++){ if(element.equalsIgnoreCase(skipElements[i])){ return Boolean.TRUE; } } return Boolean.FALSE; } private static void removeAllDuplicate(){ for(int i = 0; i &lt; skipElements.length; i++){ if(skipElements[i] != null){ removeFromList(skipElements[i]); } } } private static void removeFromList(String element){ if(list.contains(element)){ list.remove(element); removeFromList(element); } } } </code></pre> <p>Which will give you 0 or more non duplicate from the list of strings.</p> <p>Other Approach with Singel Variable:</p> <h1>2:</h1> <pre><code>public class TestDuplicateWithOneVariable { /** * @param args */ static List&lt;String&gt; list = new ArrayList&lt;String&gt;(0); private static int stop = 0; public static void main(String[] args) { list.add("xyz"); list.add("xyz"); list.add("xyz"); list.add("pqrs"); list.add("pqrs"); list.add("abcd"); list.add("Test"); while(stop &gt;= 0){ if(list.size() &gt; 0 &amp;&amp; list.size() &gt; stop){ if(isDuplicate(list.get(stop))){ removeFromList(list.get(stop)); } }else{ stop = -1; } } System.out.println("Non Duplicate--&gt;"+list); } private static void removeFromList(String element){ if(list.contains(element)){ stop = 0; list.remove(element); removeFromList(element); } } private static boolean isDuplicate(String element){ list.remove(element); if(list.contains(element)){ return Boolean.TRUE; }else{ list.add(stop,element); stop++; return Boolean.FALSE; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload