The issue of computing efficiency

I'm curious about computational efficiency. In this example, I'm going to use Java, but this is a general computational issue. Suppose I have a string, and I want to get the value of the first letter of the string as a string. Therefore i can do

String firstletter = String.valueOf(somestring.toCharArray()[0]);

Or I could do:

char[] stringaschar = somestring.toCharArray();
char firstchar = stringaschar[0];
String firstletter = String.valueOf(firstchar);

My question is, are the two methods essentially the same, computationally? I mean, in the second case, I obviously had to create 2 intermediate variables that would be temporarily stored in memory (stack?). But, first of all, the computer will still have to create the same variables, implicitly, right? And the number of operations does not change. I think both ways are the same. But I would like to know for sure.

+5
source share
4

, AFAIK.

, , , , (, ).

-, , . /.

. . , , ( , -, ...). . , //P-/ , THAT- .

, Black Boxes. , Black Box - , , . , , , .

( , , , , , ) , , , (BTW, - , , , ). , , . ... . , . . , .

Linux, , .

!

NB: , . : , , , , , , - " ", /, et c, et c, et c.

, , . .

+1

. , .

+4

, Java - . , -.

+2

. , , . , , .

+2

All Articles