所以我注意到了一些事情。
在codingbat上做递归方法时,我查看了:
String abc = "abc";
String mod = abc.substring(1);
System.out.println(mod); //prints "bc"
所以我想:
嘿,为什么不对数组使用类似子字符串的方法?
例如:
String[] abc = {"a", "b", "c"};
String[] mod = abc[1, str.length];
for(int i = 0; i < mod.length; i++){
System.out.print(mod[i]);
if(i + 1 != mod.length){
System.out.print(", ");
}
}
// This would print out: "b, c"
因此,正如您从中看到的,它就像 substring 方法,因为它将第一个数组中的对象从开始索引到结束索引添加到第二个数组,但不包括结束索引(避免越界异常) .
这将如何进行,因为我似乎找不到控制“[]”的类,因为必须有一些东西来规范它们,因为它们不只是“在那里”,它们必须添加到其中某种方式。
感谢任何建设性的批评和反馈。
FirexRanger8
最佳答案
How would this be going around to be made since I cannot seem to find the class that controls the "[ ]"'s since something has to regulate them because they aren't just "there" they had to be added in some way.
它们“就在那里”,因为它们被硬编码为语言和平台的一部分。
如果您想更改语言处理数组的方式,则必须更改 Java 编译器。如果您想更改它们在执行时的行为方式,则必须更改 JVM...
关于java - 使用列表声明数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7843077/