java conversion between the set and the use of arrays to re-set

int Result = 0 ;
         // definition can be set to the heavy set 
        the Set <String> = idSet new new HashSet <String> ();
         IF (users.length> 0 ) {
            List    list=Arrays.asList(users);
            for(IUserObject user:users){
                idSet.add(user.getUserId()+user.getUserName()+user.getUserRemoteIP());
            }
              result= idSet.size(); 
        }
        return result;

important point:

When re-set to an object to which the object if the custom property is the same as a processing object

iterator objects list using the same process (same attribute is determined in accordance with all of the defined objects must override toString method contains method before use)

IUserObject[] result=null;
        if(users.length>0){
             List infolist = new ArrayList();
             List    list=Arrays.asList(users); 
             Iterator it = list.iterator();
             while (it.hasNext()) {

                 IUserObject obj = (IUserObject) it.next();

                    if(!infolist.contains(obj)){
                        infolist.add(obj);
                    }
             }
             result=(IUserObject[]) infolist.toArray(new IUserObject[infolist.size()]);
        }
        return result;

Converted into an array using a set of methods asList

String[] array = new String[] {"zhu", "wen", "tao"};
    // String array to a List collection
    List<String> mlist = Arrays.asList(array);
    // Output List collection
    for (int i = 0; i < mlist.size(); i++) {
        System.out.println("mlist-->" + mlist.get(i));
    }

 

The list turn into an array

1、Object[] toArray();

 Usage 1
        List<String>  stringList2 = new ArrayList<>();
        stringList2.add("A");
        stringList2.add("B");
        stringList2.add("C");
        Object[] objectArray  = stringList2.toArray();

2、<T> T[] toArray(T[] a);

List<String> stringList = new ArrayList<>();
        stringList.add("A");
        stringList.add("B");
        stringList.add("C");
        String[] stringArray = stringList.toArray(new String[stringList.size()]);

  

Precautions:

Some data types are not so strong turn of array types must first be defined during the conversion eg: strong array can not turn into a String [] array; unless the array initialization when he points to a String [] array

My micro-channel public numbers we can look at welcome message, know what make friends Ha!

Guess you like

Origin www.cnblogs.com/wwwcf1982603555/p/11688116.html