Tutorial by Examples: cas

// Java: List<String> myList = Arrays.asList("a1", "a2", "b1", "c2", "c1"); myList.stream() .filter(s -> s.startsWith("c")) .map(String::toUpperCase) .sorted() .forEach(System.out::println); // C1 ...
"string".upcase # => "STRING" "STRING".downcase # => "string" "String".swapcase # => "sTRING" "string".capitalize # => "String" These four methods do not modify the original receiver. For exampl...
interface IFoo { } class Foo : IFoo { } class Bar : IFoo { } var item0 = new Foo(); var item1 = new Foo(); var item2 = new Bar(); var item3 = new Bar(); var collection = new IFoo[] { item0, item1, item2, item3 }; Using OfType var foos = collection.OfType<Foo>(); // result: IEnum...
To convert a String to uppercase, use uppercaseString: NSString *myString = @"Emphasize this"; NSLog(@"%@", [myString uppercaseString]; // @"EMPHASIZE THIS" To convert a String to lowercase, use lowercaseString: NSString *myString = @"NORMALIZE this"; N...
Dart has a switch case which can be used instead of long if-else statements: var command = 'OPEN'; switch (command) { case 'CLOSED': executeClosed(); break; case 'OPEN': executeOpen(); break; case 'APPROVED': executeApproved(); break; case 'UNSURE': ...
A case class is a class with a lot of standard boilerplate code automatically included. One benefit of this is that Scala makes it easy to use extractors with case classes. case class Person(name: String, age: Int) // Define the case class val p = Person("Paola", 42) // Instantiate a v...
Every case class defines an extractor that can be used to capture the members of the case class when pattern matching: case class Student(name: String, email: String) def matchStudent1(student: Student): String = student match { case Student(name, email) => s"$name has the following...
Ruby uses the case keyword for switch statements. As per the Ruby Docs: Case statements consist of an optional condition, which is in the position of an argument to case, and zero or more when clauses. The first when clause to match the condition (or to evaluate to Boolean truth, if the condi...
To make all the characters in a String uppercase or lowercase: 2.2 let text = "AaBbCc" let uppercase = text.uppercaseString // "AABBCC" let lowercase = text.lowercaseString // "aabbcc" 3.0 let text = "AaBbCc" let uppercase = text.uppercased() // &qu...
SELECT UPPER('HelloWorld') --returns 'HELLOWORLD' SELECT LOWER('HelloWorld') --returns 'helloworld'
The -CaseSensitive parameter enforces switch statements to perform exact, case-sensitive matching against conditions. Example: switch -CaseSensitive ('Condition') { 'condition' {'First Action'} 'Condition' {'Second Action'} 'conditioN' {'Third Action'} } Output: Second Act...
One feature provided for free by case classes is an auto-generated equals method that checks the value equality of all individual member fields instead of just checking the reference equality of the objects. With ordinary classes: class Foo(val i: Int) val a = new Foo(3) val b = new Foo(3) prin...
PHP will generally correctly guess the data type you intend to use from the context it's used in, however sometimes it is useful to manually force a type. This can be accomplished by prefixing the declaration with the name of the required type in parenthesis: $bool = true; var_dump($bool); // bool...
The boolean type cannot be cast to/from any other primitive type. A char can be cast to/from any numeric type by using the code-point mappings specified by Unicode. A char is represented in memory as an unsigned 16-bit integer value (2 bytes), so casting to byte (1 byte) will drop 8 of those bits (...
Numeric primitives can be cast in two ways. Implicit casting happens when the source type has smaller range than the target type. //Implicit casting byte byteVar = 42; short shortVar = byteVar; int intVar = shortVar; long longVar = intvar; float floatVar = longVar; double doubleVar = floatVar...
As with primitives, objects can be cast both explicitly and implicitly. Implicit casting happens when the source type extends or implements the target type (casting to a superclass or interface). Explicit casting has to be done when the source type is extended or implemented by the target type (ca...
A Broadcast receiver is an Android component which allows you to register for system or application events. A receiver can be registered via the AndroidManifest.xml file or dynamically via the Context.registerReceiver() method. public class MyReceiver extends BroadcastReceiver { @Override ...
Intents can be used to broadcast messages to other components of your application (such as a running background service) or to the entire Android system. To send a broadcast within your application, use the LocalBroadcastManager class: Intent intent = new Intent("com.example.YOUR_ACTION"...
An alternative to extending Enumeration is using sealed case objects: sealed trait WeekDay object WeekDay { case object Mon extends WeekDay case object Tue extends WeekDay case object Wed extends WeekDay case object Thu extends WeekDay case object Fri extends WeekDay case objec...
C# allows user-defined types to control assignment and casting through the use of the explicit and implicit keywords. The signature of the method takes the form: public static <implicit/explicit> operator <ResultingType>(<SourceType> myType) The method cannot take any more argu...

Page 2 of 14