add value of comparision
This commit is contained in:
parent
06bf1155e8
commit
5ca5a1e8e7
|
@ -0,0 +1,6 @@
|
|||
## Java String Conversions
|
||||
|
||||
This module contains articles about string conversions from/to another type.
|
||||
|
||||
### Relevant Articles:
|
||||
- [String.valueOf() vs. Object.toString()](https://www.baeldung.com/string-valueof-vs-object-tostring/)
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-string-conversions-3</artifactId>
|
||||
<name>core-java-string-conversions-3</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<finalName>core-java-string-conversions-3</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,17 @@
|
|||
package com.baeldung.valueofcomparison;
|
||||
|
||||
public class Student {
|
||||
|
||||
public String name;
|
||||
public int age;
|
||||
|
||||
public Student(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Student(" + name + ", age " + age + ')';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.baeldung.valueofcomparison;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ValueOfUnitTest {
|
||||
|
||||
@Test
|
||||
void whenCallingValueOf_thenMapToString() {
|
||||
char[] exampleCharArray = {'a', 'b', 'c'};
|
||||
Student alice = new Student("Alice", 5);
|
||||
|
||||
assertEquals("true", String.valueOf(true));
|
||||
assertEquals("a", String.valueOf('a'));
|
||||
assertEquals("abc", String.valueOf(exampleCharArray));
|
||||
assertEquals("123.935", String.valueOf(123.935));
|
||||
assertEquals("2222.3", String.valueOf(2222.3f));
|
||||
assertEquals("2222", String.valueOf(2222));
|
||||
assertEquals("123456789", String.valueOf(123456789L));
|
||||
assertEquals("123456789", String.valueOf(123456789L));
|
||||
assertEquals("Student(Alice, age 5)", String.valueOf(alice));
|
||||
}
|
||||
}
|
|
@ -134,6 +134,7 @@
|
|||
<module>core-java-string-apis-2</module>
|
||||
<module>core-java-string-conversions</module>
|
||||
<module>core-java-string-conversions-2</module>
|
||||
<module>core-java-string-conversions-3</module>
|
||||
<module>core-java-string-operations</module>
|
||||
<module>core-java-string-operations-2</module>
|
||||
<module>core-java-regex</module>
|
||||
|
|
Loading…
Reference in New Issue