Java For Testers: Learn Java fundamentals fast by Alan Richardson
Author:Alan Richardson [Richardson, Alan]
Language: eng
Format: epub
Publisher: Compendium Developments Ltd
Published: 2015-03-01T05:00:00+00:00
Bob said "hello" to his cat's friend
This is a single backslash \
Exercise: Try using the other escape characters
Experiment with some @Test methods which use the other escape characters in a string e.g. "\t", "\b",
"\n", "\r" and see the effect when you use System.out.println to print to the console output.
String Concatenation
We have already seen as a method of concatenating strings. The is also useful as a way of adding primitives and other objects on to the String.
String ps1 = "This is " "String2";
assertThat(ps1, is("This is String2"));
String ps2 = "This is " 4;
assertThat(ps2, is("This is 4"));
The String class has a concat method which allows us to concatenate other strings. This does not allow us to concatenate other objects on to the String.
String thisIs = "This is ";
String s1 = thisIs.concat("String1");
assertThat(s1, is("This is String1"));
Converting to/from a String
Converting to a String with toString
Most classes override the toString method to provide a way of creating a String representation of the object.
This provides a useful way of converting to a String, and this is the method called when you concatenate a String with a different type using .
For primitive types, the associated object version is used e.g. for int the Integer.toString is used.
String intConcatConvert = "" 1;
assertThat(intConcatConvert, is("1"));
String integerIntConvert = Integer.toString(2);
assertThat(integerIntConvert, is("2"));
The String class itself has the valueOf method which takes objects and primitives and converts them to a String. For objects, the object’s toString method is used for the conversion.
String integerStringConvert = String.valueOf(3);
assertThat(integerStringConvert, is("3"));
In addition you can convert from byte[] and char[] (and other objects) to a String using the String constructor.
Converting from a String
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(12398)
Hello! Python by Anthony Briggs(9751)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9637)
The Mikado Method by Ola Ellnestam Daniel Brolund(9632)
Dependency Injection in .NET by Mark Seemann(9162)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8147)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7653)
Grails in Action by Glen Smith Peter Ledbrook(7565)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7390)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6279)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(6233)
Microservices with Go by Alexander Shuiskov(5998)
Practical Design Patterns for Java Developers by Miroslav Wengner(5911)
Test Automation Engineering Handbook by Manikandan Sambamurthy(5879)
Angular Projects - Third Edition by Aristeidis Bampakos(5221)
Kotlin in Action by Dmitry Jemerov(4918)
The Art of Crafting User Stories by The Art of Crafting User Stories(4796)
NetSuite for Consultants - Second Edition by Peter Ries(4761)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(4572)
