I just announced the new Spring 5 modules in REST With Spring:

>> CHECK OUT THE COURSE

This article is part of a series:
• Java String.String()
• Java String.valueOf()
• Java String.codePointCount()
• Java String.codePointAt()
• Java String.concat()
• Java String.contains()
• Java String.copyValueOf()
• Java String.endsWith()
• Java String.format()
• Java String.getBytes()
• Java String.indexOf()
• Java String.intern()
• Java String.isEmpty()
• Java String.lastIndexOf()
• Java String.regionMatches()
• Java String.replace()
• Java String.replaceAll()
• Java String.split()
• Java String.startsWith()
• Java String.subSequence()
• Java String.substring()
• Java String.toLowerCase()
• Java String.toUpperCase()
• Java String.trim()
• Java String.valueOf()

The method valueOf() has several overloads that accept one parameter of different types and convert them to a String. Examples include boolean, char, char array, double, int and long. We can also convert a part of a char array to a String by passing:

  • offset – the index of the character to start converting from
  • count – the number of characters to convert

Available Signatures

public static String valueOf(boolean b)
public static String valueOf(char c)
public static String valueOf(char[] data)
public static String valueOf(char[] data, int offset, int count)
public static String valueOf(double d)
public static String valueOf(float f)
public static String valueOf(int i)
public static String valueOf(long l)
public static String valueOf(Object obj)

Example

@Test
public void whenCallValueOf_thenCorrect() {
    long l = 200L;
    
    assertEquals("200", String.valueOf(l));
}

I just announced the new Spring 5 modules in REST With Spring:

>> CHECK OUT THE LESSONS