【问题标题】:Java: change an element in a prepopulated List of string arrayJava:更改字符串数组的预填充列表中的元素
【发布时间】:2011-02-28 23:03:26
【问题描述】:

我已经在 storeInv 中填充了一个字符串数组列表。如何更改字符串数组中的特定元素?比如下面的代码……

谢谢=]

List <String[]> storeInv ;  //assume already populated with elements
String[] store = storeInv.get(5);
store[1] = 123;

store.set(5, store[1]);  //this gives me an error.

【问题讨论】:

  • store[1] = 123; 不会给你一个错误?
  • @battousai622:你的意思是像 store[5] = store[1]
  • 我很确定你的意思是 storeInv.set(5, store); 但你不需要,因为它已经在那里了。

标签: java string list arrays set


【解决方案1】:
List <String[]> storeInv = ...
String[] store = storeInv.get(5);

// This updates an element in one of the arrays.  (You cannot
// assign an integer literal to a String or a String array element.)
store[1] = "123";

// Compilation error!  'store' is an array, so there is no 'set' method.
store.set(5, store);

// This updates an array in the list ... but in this
// case it is redundant because the 5th list element
// is already the same object as 'store'.
storeInv.set(5, store);

【讨论】:

  • set 方法对我不起作用。我无法让它显示在 Eclipse 的自动完成功能中,我尝试在 String[] 上使用它。嗯?
猜你喜欢
  • 1970-01-01
  • 2019-11-24
  • 1970-01-01
  • 2013-10-22
  • 1970-01-01
  • 1970-01-01
  • 2017-06-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多