| |

VerySource

 Forgot password?
 Register
Search
View: 2089|Reply: 12

Simple little question ~!

[Copy link]

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-2-23 19:00:02
| Show all posts |Read mode
public void Methond (List list1, List list2) {
 if (list1.size> list2.size)
  {
   .........
  }
}

public void Methond (List list1, List list2) {
  int size1 = list1.size;
  int size2 = list2.size;
 if (size1> size2)
  {
   .........
  }
What is the difference between these two works?
}
Reply

Use magic Report

0

Threads

13

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-5-10 14:45:01
| Show all posts
No difference
Reply

Use magic Report

0

Threads

1

Posts

0.00

Credits

Newbie

Rank: 1

Credits
0.00

 China

Post time: 2020-5-10 15:59:28
| Show all posts
No difference
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-10 23:30:02
| Show all posts
What difference do you want it to have.
Reply

Use magic Report

0

Threads

9

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-5-16 19:15:01
| Show all posts
The only difference is the newly defined variable, which increases the overhead
Other things
Reply

Use magic Report

0

Threads

9

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 Invalid IP Address

Post time: 2020-5-17 22:30:01
| Show all posts
The difference is different, but the if () statement has little effect here, because list1.size is used to traverse the list every time to get its size. If you repeatedly use the size attribute of list, it is best to First take it out and put it in the int variable. For example, if there is such a statement for (; list.size;) {} It is better to use the latter method
Reply

Use magic Report

0

Threads

11

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-5-23 20:30:01
| Show all posts
The difference is ...
There are two more int spaces in the memory
Reply

Use magic Report

0

Threads

23

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-5-25 08:00:01
| Show all posts
4 bytes of memory are wasted. The former is released after the comparison, and the latter is released after the function is executed. I think it is not true to discuss this issue.
Reply

Use magic Report

3

Threads

17

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-6-24 15:15:01
| Show all posts
No difference
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Invalid IP Address

Post time: 2020-8-19 15:30:01
| Show all posts
list1.size ==> list1.size()
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list