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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:12:08+00:00 2026-06-12T02:12:08+00:00

I have this Java app that I’m doing some web scraping with using the

  • 0

I have this Java app that I’m doing some web scraping with using the JSoup library. I’m using the library and it’s returning a collection of Strings 6 of them. I need to map these 6 random strings to properties on an object. I know which order the strings are coming in and what number maps to what property. I don’t feel like my approach is the best way to handle this. It feels lose, readability sucks, and I’m just wondering if there’s a better way to do this. I was thinking using enum’s or something alone those lines. Long story short here’s a code snippet. Thanks for any help.

List<String> strings = JSoup.getStrings();
Car car = new Car();
int i = 0;
for(String s : strings) {
    switch (i) {
        case 0:
            car.setMake(s);
            break;
        case 1:
            car.setModel(s);
            break;
        .....
    }
    i++;
}
  • 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-12T02:12:09+00:00Added an answer on June 12, 2026 at 2:12 am

    Since this question is about best practices, you should consider providing a constructor in Car that takes a List of Strings as an input. The constructor will then initialize the fields for the car from the List of Strings one by one because that’s what constructors are for any way. This means that the code for populating your car instance will now be in a single place, i.e inside the Car class.

    This approach will eliminate the need for the code that creates a Car instance to manually initialize the Car instance. No matter how many different classes create a Car, the initialization code will not be duplicated in each of these classes. Placing the initialization code inside car itself promotes reusability. Isn’t that what classes are written for?

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

Sidebar

Related Questions

I have a Java web app that I'm developing, using JBoss Seam as the
I have a Java app that fetches a relatively small .zip file using a
I have a Java web app that I develop on a Windows machine and
I have a java web app that makes back-end use of a third-party web
So this is a really strange problem. I have a Java app that acts
I have a Java app that needs to integrate with a 3rd party library.
I have a web app that I am deploying to Tomcat 7.0 using Eclipse
I have a Java app that makes use of some native code, and it's
I have a standalone Java app that has some licensing code that I want
I have an a Java Android app that calls different activities. I thought this

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.