将字符串数组转换为长数组

Fly*_*Dev 2 java long-integer

我想将Info_TimeD1[]字符串数组中的值转换为长数组并存储在ohh[].I中发现错误,我无法通过这种情况.

String[] Info_TimeD1;  
String[] ohh;
int i;

int L1 = Info_TimeD1.length;

    for(int i=0;i<L1;i++)
{
     Long Timestamp1[i] = Long.parseLong(Info_TimeD1[i]); // error this line
     ohh[i] = getDateCurrentTimeZone1(Timestamp1[i]);
}
Run Code Online (Sandbox Code Playgroud)

Jon*_*eet 7

这不是有效的Java:

Long Timestamp1[i] = // anything...
Run Code Online (Sandbox Code Playgroud)

你要做的事情并不是很清楚 - 如果你试图填充现有数组的单个元素,你应该使用:

Timestamp1[i] = ...
Run Code Online (Sandbox Code Playgroud)

如果您尝试声明一个新变量,则应使用:

long timestamp = ...
Run Code Online (Sandbox Code Playgroud)

目前你的代码介于两者之间.

顺便说一句,我强烈建议您开始遵循Java命名约定.


Ell*_*sch 5

你有几个不同的问题,

String[] Info_TimeD1;
String[] ohh;
// int i; <-- Duplicate variable with your for loop.

int L1 = Info_TimeD1.length;
Long[] Timestamp1 = new Long[L1]; // <-- Declare your array.
for (int i = 0; i < L1; i++) {
    Timestamp1[i] = Long.parseLong(Info_TimeD1[i]); // <-- Fixed.
    ohh[i] = getDateCurrentTimeZone1(Timestamp1[i]);
}
Run Code Online (Sandbox Code Playgroud)