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 7643199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:23:17+00:00 2026-05-31T09:23:17+00:00

I have an algorithm that reads from the stdout into a string variable called

  • 0

I have an algorithm that reads from the stdout into a string variable called ‘name’ and then creates a string array that stores the name..I tried to do this in java but first, I don’t know how to pass the name into the array. in C or C++, i could have just easily done this : strcpy(arr, name); but these are string types and there are no c_str() equivalent in Java that I have seen. Please, how do I do this?

      .... //codes are here...
      System.out.Println("enter your name and press enter:");
      BufferedReader br = new BufferedReader(InputStreamReader(System.in));
      String name = null;
  try
    {
      name = br.readLine();
      String[] arr = new String[name.length];
       //wish this was C++;
        strcpy(arr.c_str(), name.c_str()); //how do you copy the name string to the arr   
                                           //string?

  }catch(IOException e)
     {
      System.out.Println(e.getMessage());
    }

    MyClass A = new MyClass(arr);
  • 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-05-31T09:23:19+00:00Added an answer on May 31, 2026 at 9:23 am

    I think you are completely mixing up stuff here.

    Either the assignment name = br.readLine() will produce an error (because readLine() returns a String not a String[]) or the expression name.length will produce a compiler error because a String does not have a property length only a method length()

    Secondly:

    String[] arr = new String[name.length];
    

    will create an array of String objects. It does not declare a String of length name.length.

    If you really want to store the value read from the Reader into an array of String objects, can directly assign this:

    String[] arr = new String[] { name };
    

    Will create an array with one element, that contains the value of the name variable.

    But I don’t see why you would want to put that String instance into an array in the first place.

    And last but not least: there is no need to copy the String you get around. You can safely work with that instance (e.g. return it from the method) because the String class is immutable in Java.

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

Sidebar

Related Questions

i have heard from a friend of mine that the best algorithm for swapping
I have a Python script that reads a file (typically from optical media) marking
I have a program that reads server information from a configuration file and would
I have a computer program that reads in an array of chars that operands
I have a Win32 application that I'm making, and it sends a string from
I have a UDP network application that reads packets sent to it and then
I have an algorithm that I believe to be secure. So the server creates
I have an algorithm that generates strings based on a list of input words.
I have an algorithm that recursively makes change in the following manner: public static
I have this algorithm that I want to implement on VB6. Sub Main() dim

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.