简体   繁体   English

如何基于Java中的数字将字符串放入数组中的特定位置?

[英]how do you put a string into a specific spot in an array based on a number in java?

How would I put a string into an array in a specific spot based on a number? 如何根据数字将字符串放入特定位置的数组中?

public Student(String firstName, String lastName, String studentNumber, int grade){
    courseTimeTable = new String[] {"Block " + courseBlock + ": " + course, "Block " + courseBlock + ": " + course};
}

public void setCourse(int block, String courseCode) {
    course = courseCode;
    courseBlock = block;
}

So how would I put the "course" into the "courseTimeTable" array based on the "courseBlock" 那么我如何基于“ courseBlock”将“课程”放入“ courseTimeTable”数组中

You will need to know the maximum size of courseTimeTable first. 您首先需要知道courseTimeTable的最大大小。

Then you can do: 然后,您可以执行以下操作:

 courseTimeTable = new String[<maximumSize>];
 courseTimeTable[courseBlock] = ...;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM