方法例子中的疑问.tochararray() [英] Doubt in method example.tochararray()

查看:107
本文介绍了方法例子中的疑问.tochararray()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解方法example.toCharArray(),我将字符串分解为字符数组,但问题是它是否将它们存储在一个新的临时数组中它只是打破它我的意思是它适用于ex的每个循环类型: -

I understand the method example.toCharArray() that i breaks the strings into arrays of chars but question is that does it store them in a new temporary array it just breaks it i mean it works for for each loop type for ex:-

String example="hello";
for (char letter:example.toCharArray);



//我的问题是例如.toCharArray为循环创建一个新的临时数组,或者它只是打破了字母并且没有存储它们。如果它没有存储它们,那么每个版本如何将它理解为数组。

***对不起这类问题,但我只想了解洞察力如何工作**

**也非常感谢您的回复!!!



我尝试过的事情:



它试图创建一个用于存储示例字母的新数组但是我的每个循环都做得很好,甚至没有创建新数组


// MY question is that is for example.toCharArray creating a new temporary array for loop or it just breaks the letter and donot store them. If it donot store them then how for each version can understand it as an array.
*** Sorry for such kind of question but i just want understand how insights work**
** Also A lot thanks for replying !!!

What I have tried:

it tried to create a new array for storing example letters but my for each loop does well even without creating a new array

推荐答案

如果在怀疑,请查看文档: Java String toCharArray()方法 [ ^ ]

清楚地说:
If in doubt, look at the documentation: Java String toCharArray() Method[^]
It clearly says:
Quote:

返回一个新分配的字符数组,其长度为该字符串的长度,其内容初始化为包含此字符串表示的字符序列。

returns a newly allocated character array, whose length is the length of this string and whose contents are initialized to contain the character sequence represented by this string.



I.e.它创建一个新的数组并填充它 - 它不是一个临时数组,而不是任何其他数组是临时的,它被分配好像它是由你声明的并且会持续很长时间。


I.e. it creates a new array and fills it - it's not a "temporary array" any more than any other array is "temporary", it's allocated as if it was declared by you and will last as long.


这篇关于方法例子中的疑问.tochararray()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆