java - 使用列表声明数组

标签 java arrays object substring declaration

所以我注意到了一些事情。

在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/

相关文章:

java - 如何为我的 java 程序按日期制定/设置时间限制

java - 使用 Java 日历

ios - Swift:返回 self 类型的数组

java - Spring 3 MVC jQuery POST 提交可变数量的数据

java - 在阻塞队列上等待时中断

java - 使用java编写两个方法min和max来查找链表中的最大值和最小值,但输入列表是整数数组

android - 如何在 android 打开 URL 连接中发送 Json 数组作为 post 参数

ios - 对象属性设置为空

javascript - OOO JavaScript : object self reference returns undefined but console shows it exists

javascript - 循环子对象