Tutorial by Examples: by

Writing bytes to an OutputStream one byte at a time OutputStream stream = object.getOutputStream(); byte b = 0x00; stream.write( b ); Writing a byte array byte[] bytes = new byte[] { 0x00, 0x00 }; stream.write( bytes ); Writing a section of a byte array int offset = 1; int length = ...
Java SE 7 byte[] bytes = { 0x48, 0x65, 0x6c, 0x6c, 0x6f }; try(FileOutputStream stream = new FileOutputStream("Hello world.txt")) { stream.write(bytes); } catch (IOException ioe) { // Handle I/O Exception ioe.printStackTrace(); } Java SE 7 byte[] bytes = { 0x48, ...
If you precede a local variable's name with an &, then the variable will be captured by reference. Conceptually, this means that the lambda's closure type will have a reference variable, initialized as a reference to the corresponding variable from outside of the lambda's scope. Any use of the v...
In this example, we can use GROUP BY not only determined the sort of the rows returned, but also what rows are returned, since we're using TOP to limit the result set. Let's say we want to return the top 5 highest reputation users from an unnamed popular Q&A site. Without ORDER BY This query ...
int x = 0; int y = 5 / x; /* integer division */ or double x = 0.0; double y = 5.0 / x; /* floating point division */ or int x = 0; int y = 5 % x; /* modulo operation */ For the second line in each example, where the value of the second operand (x) is zero, the behaviour is undefine...
Let's say you want to generate counts or subtotals for a given value in a column. Given this table, "Westerosians": NameGreatHouseAllegienceAryaStarkCerceiLannisterMyrcellaLannisterYaraGreyjoyCatelynStarkSansaStark Without GROUP BY, COUNT will simply return a total number of rows: SELE...
SELECT DisplayName, JoinDate, Reputation FROM Users ORDER BY JoinDate, Reputation DisplayNameJoinDateReputationCommunity2008-09-151Jeff Atwood2008-09-1625784Joel Spolsky2008-09-1637628Jarrod Dixon2008-10-0311739Geoff Dalgas2008-10-0312567
// Java: String joined = things.stream() .map(Object::toString) .collect(Collectors.joining(", ")); // Kotlin: val joined = things.joinToString() // ", " is used as separator, by default
// Java: Map<Department, List<Employee>> byDept = employees.stream() .collect(Collectors.groupingBy(Employee::getDepartment)); // Kotlin: val byDept = employees.groupBy { it.department }
// Java: Map<Department, Integer> totalByDept = employees.stream() .collect(Collectors.groupingBy(Employee::getDepartment, Collectors.summingInt(Employee::getSalary))); // Kotlin: val totalByDept = employees.groupBy { it.dept }.mapValues { it.v...
// Java: Map<Person.Sex, List<String>> namesByGender = roster.stream().collect( Collectors.groupingBy( Person::getGender, Collectors.mapping( Person::getName, Collectors.toList()))); // ...
// Java: Map<Integer, String> map = persons .stream() .collect(Collectors.toMap( p -> p.age, p -> p.name, (name1, name2) -> name1 + ";" + name2)); System.out.println(map); // {18=Max, 23=Peter;Pamela, ...
C11 Reading an object will cause undefined behavior, if the object is1: uninitialized defined with automatic storage duration it's address is never taken The variable a in the below example satisfies all those conditions: void Function( void ) { int a; int b = a; } 1 (Quo...
You can see what "hunks" of work would be staged for commit using the patch flag: git add -p or git add --patch This opens an interactive prompt that allows you to look at the diffs and let you decide whether you want to include them or not. Stage this hunk [y,n,q,a,d,/,s,e,?]? ...
Python 2.x2.7 In Python 2 there are two variants of string: those made of bytes with type (str) and those made of text with type (unicode). In Python 2, an object of type str is always a byte sequence, but is commonly used for both text and binary data. A string literal is interpreted as a byte s...
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...
You can use a column's number (where the leftmost column is '1') to indicate which column to base the sort on, instead of describing the column by its name. Pro: If you think it's likely you might change column names later, doing so won't break this code. Con: This will generally reduce readabilit...
Lets assume we have some Film model: public class Film { public string Title { get; set; } public string Category { get; set; } public int Year { get; set; } } Group by Category property: foreach (var grp in films.GroupBy(f => f.Category)) { var groupCategory = grp.Key; ...
Overview In order to debug Java classes that are called during MATLAB execution, it is necessary to perform two steps: Run MATLAB in JVM debugging mode. Attach a Java debugger to the MATLAB process. When MATLAB is started in JVM debugging mode, the following message appears in the command wi...
Match any single character within the specified range (e.g.: [a-f]) or set (e.g.: [abcdef]). This range pattern would match "gary" but not "mary": SELECT * FROM Employees WHERE FName LIKE '[a-g]ary' This set pattern would match "mary" but not "gary": SEL...

Page 2 of 23