2

I want convert value in Info_TimeD1[] from string array to long array and store in ohh[].I found error and I can't pass this case.

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]);
}
2
  • 1
    What error did you find? Commented Mar 21, 2014 at 15:20
  • Type mismatch: cannot convert from long to Long[] Commented Mar 21, 2014 at 15:22

2 Answers 2

7

This isn't valid Java:

Long Timestamp1[i] = // anything...

It's not really clear what you're trying to do - if you're trying to populate a single element of an existing array, you should use:

Timestamp1[i] = ...

If you're trying to declare a new variable, you should use:

long timestamp = ...

Currently your code is somewhere between the two.

As an aside, I would strongly advise you to start following Java naming conventions.

Sign up to request clarification or add additional context in comments.

Comments

6

You have a few different issues,

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]);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.