java - Removing an element from 3 common elements in android -


removing common value arraylist. consider have 1 arraylist shown below

arraylist1= [u1,u2,u3,.gy,.gy,.gy,u4,.gy,u5,u6,.gy,.gy,.gy]

my result should be

arraylist1= [u1,u2,u3,.gy,.gy,u4,.gy,u5,u6,.gy,.gy]

could please me out.

thanks in advance

you can try this:

public static void main(string[] args) {     list<string> list = arrays.aslist("u1","u2","u3",".gy",".gy",".gy","u4",".gy","u5","u6",".gy",".gy",".gy");     system.out.println(removecommon(list)); // [u1, u2, u3, .gy, .gy, u4, .gy, u5, u6, .gy, .gy] }  static list<string> removecommon(list<string> list) {     list<string> result = new arraylist<>(list);     (int = 0; < list.size() - 2; i++) {         if (list.get(i).equals(list.get(i + 1)) && list.get(i).equals(list.get(i + 2))) {             result.remove(i);         }     }     return result; } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -