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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:59:57+00:00 2026-05-27T06:59:57+00:00

I need to create a summary table at the end of a log with

  • 0

I need to create a summary table at the end of a log with some values that
are obtained inside a class. The table needs to be printed in fixed-width
format. I have the code to do this already, but I need to limit Strings,
doubles and ints to a fixed-width size that is hard-coded in the code.

So, suppose I want to print a fixed-width table with

    int,string,double,string
    int,string,double,string
    int,string,double,string
    int,string,double,string

    and the fixed widths are: 4, 5, 6, 6.

If a value exceeds this width, the last characters need to be cut off. So
for example:

    124891, difference, 22.348, montreal

the strings that need to be printed ought to be:

    1248 diffe 22.348 montre

I am thinking I need to do something in the constructor that forces a
string not to exceed a certain number of characters. I will probably
cast the doubles and ints to a string, so I can enforce the maximum width
requirements.

I don’t know which method does this or if a string can be instantiated to
behave taht way. Using the formatter only helps with the
fixed-with formatting for printing the string, but it does not actually
chop characters that exceed the maximum length.

  • 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-27T06:59:57+00:00Added an answer on May 27, 2026 at 6:59 am

    Use this to cut off the non needed characters:

    String.substring(0, maxLength); 
    

    Example:

    String aString ="123456789";
    String cutString = aString.substring(0, 4);
    // Output is: "1234" 
    

    To ensure you are not getting an IndexOutOfBoundsException when the input string is less than the expected length do the following instead:

    int maxLength = (inputString.length() < MAX_CHAR)?inputString.length():MAX_CHAR;
    inputString = inputString.substring(0, maxLength);
    

    If you want your integers and doubles to have a certain length then I suggest you use NumberFormat to format your numbers instead of cutting off their string representation.

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

Sidebar

Related Questions

I need to write a report that generates summary totals against a table with
I need to create a summary from 3 different tables, 1 parent table, 2
I have a handle-based class that I need to create a vector of. An
I need to create an HTML table which has fixed column widths, say 200px
i need create a variable with parent subclass. Example: Parent Class <?php class parentClass
I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
I need to create a html parser, that given a blog url, it returns
I'm currently creating an external table like that: CREATE EXTERNAL TABLE site_datatype ( ....
I have a set of conditions that I need to use to retrieve some
I need create custom dialog and put JPanel into it. Is it possible?

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.