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

  • Home
  • SEARCH
  • 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 7597527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:10:42+00:00 2026-05-30T22:10:42+00:00

Since I am new to Java, I need some help about some basic things

  • 0

Since I am new to Java, I need some help about some basic things on Java.
I have two questions. They may be very simple(they are at least in C++), but I couldn’t figure out how to do it in Java.

(i) How to split line with comma separated values into separate strings?

Suppose I have an input(text) file like:

 zoo,name,cszoo,address,miami  

    ...,...,...,....

I want to read the input line by line from file and get the strings between commas for each line

(ii) Calling sub class constructor

If I have a superclass called Animal and a subclasses called Dog and Cat. While I read them from input, I put them into a Vector as an Animal. But I need to call their constructor as if they are Dog or Cat. How do I do it in Java

  • 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-30T22:10:43+00:00Added an answer on May 30, 2026 at 10:10 pm
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    // or, to read from a file, do:
    // BufferedReader br = new BufferedReader(new FileReader("file.txt"));
    String line;
    while ((line = br.readLine()) != null) {
        String[] a = line.split(",");
    
        // do whatever you want here
        // assuming the first element in your array is the class name, you can do this:
        Animal animal = Class.forName(a[0]).newInstance();
    
        // the problem is that that calls the zero arg constructor. But I'll 
        // leave it up to you to figure out how to find the two arg matching
        // constructor and call that instead (hint: Class.getConstructor(Class[] argTypes))
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Java, and I need some help working on this program. This
Need some guidance. I have java webstart app and I want it to connect
Since starting at a new company I've noticed that they use unity cpp files
Ever since I installed emacs on a new machine I have seen an ugly
I am new to Oracle. Since we have rewritten an earlier application , we
This question might seem very specific but I am in need of some ideas
iI have some trouble getting sth like this to work in java: public class
Today I started work on a small Java app. I have some experience with
I'm just starting a new GAE project, and I see they've done some sprucing
I'm still pretty new to c++ (coming over from java). I have a stl

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.