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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:28:34+00:00 2026-05-31T16:28:34+00:00

BEFORE: EUTQQGOPED AFTER: EUT-QQG-OPED The example below is what I came up with to

  • 0

BEFORE:

EUTQQGOPED

AFTER:

EUT-QQG-OPED

The example below is what I came up with to add ‘-‘ to a 10 character String as part of a readability requirement. The formatting pattern is similar to how a U.S Social Security Number is often formatted.

Is there a simpler, less verbose way of accomplishing the additional format?

public static void main(String[] args){
        String pin = "EUTQQGOPED";
        StringBuilder formattedPIN = new StringBuilder(pin);
        formattedPIN = formattedPIN.insert(3, '-').insert(7, '-');
        //output is EUT-QQG-OPED
        println formattedPIN
}
  • 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-31T16:28:36+00:00Added an answer on May 31, 2026 at 4:28 pm

    I think what you’ve done is the best way to do it, however you could make it more elegant by simply in-lining everything, as follows:

    public static void main(String[] args) {
        println new StringBuilder("EUTQQGOPED").insert(6, '-').insert(3, '-');
    }
    

    This kind of in-lining is possible due to StringBuilder providing a fluent interface (which allows method chaining).

    Also note the transposition of the inserts, because the order you had them in means the first insert affects the parameters of the second insert. By ordering them largest-first means they are basically independent of each other.

    And there’s always… “less code == good” (as long as it’s still readable, and in this case it is IMHO more readable)

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

Sidebar

Related Questions

Before spending any time reading this, see the self-answer below. The problem was invalid
Before i start i will divide the problem into two parties: PART 1 :
Before I ask the question I like to provide the code for clarity. Below
Before the user has logged in with Facebook the app looks like After the
Before anyone suggests scrapping the table tags altogether, I'm just modifying this part of
Before Django 1.0 there was an easy way to get the admin url of
Before answering, it is not as easy question as you might have thought about
Before you start flaming, I'm going to tell you that I am trying to
Before I roll my own Queue using NSMutableArray , I'd like to know if
Before I begin I'll freely admit it's something in my code but it's not

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.