-1

I am making a tour guide app using fragments and tablayout i made a viewpager adapter to navigate through the tabs in the getItem method i use If else statement like this

   if (position == 0) {
        return new InfoFragment();
    } else if (position == 1) {
        return new HotelsFragment();
    } else if (position == 2) {
        return new RestaurantsFragment();
    } else {
        return new TemplesFragment();
    }

and I notice that I also can use Switch statement like this

 switch (position) {
        case 0:
            return new InfoFragment();
        case 1:
            return new HotelsFragment();
            case 2:
                return new RestaurantsFragment();
        default:
            return new TemplesFragment();

    }

so I wonder which one should I use.. Thanks in advance ..

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
hesham ahmed
  • 141
  • 1
  • 10

1 Answers1

0

The switch is considered faster that's the only difference I know. If I have to choose I will choose switch.

Atul Chaudhary
  • 3,698
  • 1
  • 31
  • 51