tags:

views:

87

answers:

5
    String lower = Name.toLowerCase();
int a = Name.indexOf(" ",0);
String first = lower.substring(0, a);
String last = lower.substring(a+1);
char f = first.charAt(0);
char l = last.charAt(0);
System.out.println(l);

how would i get the F and L variables converted to uppercase.

+1  A: 
f = Character.toUpperCase(f);
l = Character.toUpperCase(l);
DaveJohnston
+3  A: 

Have a look at the java.lang.Character class, it provides a lot of useful methods to convert or test chars.

Andreas_D
+1 I like the answers that providers the user with a reference to go seek the answer
Anthony Forloney
+1  A: 

You can use Character#toUpperCase() for this.

char fUpper = Character.toUpperCase(f);
char lUpper = Character.toUpperCase(l);

It has however some limitations since the world is aware of many more characters than can ever fit in 16bit char range. See also the following excerpt of the javadoc:

Note: This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the toUpperCase(int) method.

BalusC
A: 

The easiest solution for your case - change the first line, let it do just the opposite thing:

String lower = Name.toUpperCase ();

Of course, it's worth to change its name too.

Roman
A: 

If you are including the apache commons lang jar in your project than the easiest solution would be to do:

WordUtils.capitalize(Name)

takes care of all the dirty work for you. See the javadoc here

Alternatively, you also have a capitalizeFully(String) method which also lower cases the rest of the characters.

Asaf