Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7738561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:17:53+00:00 2026-06-01T08:17:53+00:00

I want to decompose a String array into Long array or List. I don’t

  • 0

I want to decompose a String array into Long array or List.
I don’t want to use Loop.

Is there any Java Method to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:17:54+00:00Added an answer on June 1, 2026 at 8:17 am

    There is no O(1) operation to “convert” a String[] (with numeric strings) to a long[]. It will always be O(n), if the loop visible or hidden in some thirdparty method.

    If you don’t want to “see” the loop, simply implement a method

    Long[] pseudoOneStepConversion(numbers);
    

    and implement

    privat Long[] pseudoOneStepConversion(String[] numbers) {
      Long[] result = new long[numbers.length];
      for (int i = 0; i < numbers.length; i++)
         result[i] = Long.parseLong(numbers[i]);
      return result;
    }
    

    We can do it recursively too – it is still O(n), less performant and doesn’t look like a loop:

    public static void main(String[] args) {
        List<Long> target = new ArrayList<Long>();
        copy(new String[]{"1", "2", "3"}, target, 0);
        System.out.println(target);
    }
    
    private static void copy(String[] source, List<Long> target, int index) {
        if (index == source.length)
            return;
        target.add(Long.parseLong(source[index]));
        copy(source, target, index+1);
    }
    

    Note – because I start getting downvotes for the recursion example: It is purely academic and not inteded for use in production code – thought, that was clear 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to decompose the number into the product of the largest square in
I want to decompose my UI into several XML Layouts. The first one would
want to know why String behaves like value type while using ==. String s1
want to ask user to input something but not want to wait forever. There
I'm trying to inject some Scala code into my existing Java app. (So, being
I wrote a software application in Java. Now I want to deliver it to
I would like a simple way to decompile Java. I want to examine the
I want to use model-based clustering to classify 1,225 time series (24 periods each).
Is there a way to deploy a Java program in a format that is
Want to know what the stackoverflow community feels about the various free and non-free

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.