Android-arraylist use

Source: Internet
Author: User

Optimize a piece of code today, as follows

intnum = 0; BooleanSkipappend =false; intTypes_ext1[] =New int[] {moduletype.type_contact, moduletype.type_message, Moduletype.type_picture,               Moduletype.type_bookmark,moduletype.type_music}; intTypes_ext2[] =New int[] {moduletype.type_contact, moduletype.type_message, Moduletype.type_picture,            Moduletype.type_bookmark,moduletype.type_calendar}; intTypes_ext3[] =New int[] {moduletype.type_contact, moduletype.type_message, Moduletype.type_picture, Moduletype.type_bookmark};if(Misgoogleorigcalendarexist &&misgoogleorigmusicexist) {num=types.length;  for(inti = 0; i < num; i++) {Types_ext[i]=Types[i]; } mylogger.loge ("YJP", "Music & Calendar is not 3rd-party"); } Else if(! (Misgoogleorigcalendarexist | |misgoogleorigmusicexist)) {num=types_ext3.length;  for(inti = 0; i < num; i++) {Types_ext[i]=Types_ext3[i]; } mylogger.loge ("YJP", "Music & Calendar is 3rd-party"); } Else if(!misgoogleorigcalendarexist &&misgoogleorigmusicexist) {num=types_ext1.length;  for(inti = 0; i < num; i++) {Types_ext[i]=Types_ext1[i]; } mylogger.loge ("YJP", "Calendar is 3rd-party"); } Else if(Misgoogleorigcalendarexist &&!)misgoogleorigmusicexist) {num=types_ext2.length;  for(inti = 0; i < num; i++) {Types_ext[i]=Types_ext2[i]; } mylogger.loge ("YJP", "Music is 3rd-party"); }

This code, in fact, is to change the elements inside the int[]. Because the int[] array is more troublesome to delete, can only rely on the loop to extract to another array. So, I thought of using list, so it's very convenient to change dynamically.

As follows

Arraylist<integer> typelist =NewArraylist<integer>();  for(inti = 0; i < types.length; i++) {Typelist.add (types[i]); }                Try{Packagemanager PM1=Getpackagemanager (); Pm1.getpackageinfo ("Com.android.calendar", packagemanager.get_activities); Misgoogleorigcalendarexist=true; } Catch(packagemanager.namenotfoundexception e) {Mylogger.loge ("YJP", "Google original Calendar not found"); }                Try{Packagemanager PM2=Getpackagemanager (); Pm2.getpackageinfo ("Com.android.music", packagemanager.get_activities); Misgoogleorigmusicexist=true; } Catch(packagemanager.namenotfoundexception e) {Mylogger.loge ("YJP", "Google original Music not found"); }                if(!misgoogleorigmusicexist)            {Typelist.remove (integer.valueof (moduletype.type_music)); }                if(!misgoogleorigcalendarexist)            {Typelist.remove (integer.valueof (Moduletype.type_calendar)); }                if(Featureoption.vanzo_oos_browser_support) {Typelist.remove (integer.valueof (Moduletype.type_bookmark))            ; }                intnum = Typelist.size ();

Android-arraylist use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.