How can I trim this?

Posted on 2006-07-17
Last Modified: 2010-03-31
How can I trim this string?  
It has a space at the end.

String username1 = (String)session.getAttribute("j_username");
Question by:g118481
  • 2
LVL 23

Assisted Solution

Ajay-Singh earned 50 total points
ID: 17124573
using trim() function should help:

String username1 = (String)session.getAttribute("j_username");
username1 = username1.trim();
LVL 86

Accepted Solution

CEHJ earned 75 total points
ID: 17124649
You need to check for null

String username1 = (String)session.getAttribute("j_username");
if (username1 != null) {
    username1 = username1.trim();

Author Comment

ID: 17124735
Thank you.
LVL 86

Expert Comment

ID: 17124745

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
basic hardware to learn oop advanced design patterns 3 88
Which is the latest version of Apache Tomcatl 3 49
for i loop in grovy 1 44
Java DateChooser? 3 29
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

932 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now