请问使用 ArrayList 如何判断其元素里头重复的值有哪几个????
如有一个 ArrayList , 其值各有
ArrayList[0]=”A”
ArrayList[1]=”B”
ArrayList[3]=”C”
ArrayList[4]=”D”
ArrayList[5]=”B”
ArrayList[6]=”B”
……….重复的值很多,想要把他们都找出来……
如何撰写程序呢
谢谢

解决方案 »

  1.   

    bool [ar.length] = bflag;
    for( int k=0 ; k<ar.Length ; k++ )
       bflag= false;
    for( int i=0 ; i<ar.Length ; i++ )
    {
       if( bflag[i] )
          continue;
       for( j=i+1 ; j<ar.length ;j++ ) 
       {
           if( ar[i] == ar[j]  )
           {
              bflag[j] = true;
              进行处理;
            }
        }}
      

  2.   

    a few ways, convert it to an array, sort it and check adjacent values, or use a hashtable, for exampleHashtable ht = new Hashtable();
    foreach (string s in YourArrayList)
    {
      int n = 0;  if (ht.Contains(s))
      {
    n = (int)ht[s];
      }  ht[s] = n + 1;
    }foreach (string s in ht.Keys)
    {
      Console.WriteLine(s);
    }
      

  3.   

    foreach好像对性能有影响。