Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating a white space

Posted on 2002-06-26
5
Medium Priority
?
178 Views
Last Modified: 2010-03-31
Is there an existing class in Java wherein I can use just say create 50 spaces and start displaying a string in the text Area?

I don't like to create a method that just loop and create a space with append the string I want.
0
Comment
Question by:bubwit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Accepted Solution

by:
Calron earned 80 total points
ID: 7112844
You probably need this to set the initial size of the TextArea, instead of just filling in spaces, you can also use the methods: setColumns(int), be sure to read the API doc of the setColumns(int) and getColumnWidth() as setting the number of columns is not the same as allowing for n characters.

If you still want to use spaces, there is no ready made class, I would do the loop, though make sure you don't loop on a String (way too slow and creates a ton of temporary string objects), use StringBuffer:

StringBuffer s = new StringBuffer();
for (int i = 0; i < 50; i++) {
  s.append(" ");
}
String finalString = s.toString();


of course you can make this more efficient by adding 2 or more spaces at a time, its just supposed to be an example
0
 
LVL 92

Expert Comment

by:objects
ID: 7112929
This should be a bit faster:

char[] spaces = new char[50];
Arrays.fill(spaces, ' ');
String s = new String(spaces);
0
 

Expert Comment

by:udaykumar22
ID: 7115965
Hi,

I think this would be the fastest ;-)

String Str = new String("                                                 ");

Regards,
Uday.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8893423
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- points to Calron

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question