Tutorial by Examples: element

Given a JList like JList myList = new JList(items); the selected items in the list can be modified through the ListSelectionModel of the JList: ListSelectionModel sm = myList.getSelectionModel(); sm.clearSelection(); // clears the selection sm.setSelectionInterval(inde...
The Iterator.remove() method is an optional method that removes the element returned by the previous call to Iterator.next(). For example, the following code populates a list of strings and then removes all of the empty strings. List<String> names = new ArrayList<>(); names.add("...
List doesn't support "random access", which means it takes more work to get, say, the fifth element from the list than the first element, and as a result there's no List.get nth list function. One has to go all the way from the beginning (1 -> 2 -> 3 -> 4 -> 5). If you need ra...
Use the HTML or <audio> element to embed video/audio content in a document. The video/audio element contains one or more video/audio sources. To specify a source, use either the src attribute or the <source> element; the browser will choose the most suitable one. Audio tag example: &...
Number of unique elements in a series: In [1]: id_numbers = pd.Series([111, 112, 112, 114, 115, 118, 114, 118, 112]) In [2]: id_numbers.nunique() Out[2]: 5 Get unique elements in a series: In [3]: id_numbers.unique() Out[3]: array([111, 112, 114, 115, 118], dtype=int64) In [4]: df = pd.Da...
From ES5.1 onwards, you can use the native method Array.prototype.filter to loop through an array and leave only entries that pass a given callback function. In the following example, our callback checks if the given value occurs in the array. If it does, it is a duplicate and will not be copied to...
var arr = [1, 2, 3, 4]; Method 1 Creates a new array and overwrites the existing array reference with a new one. arr = []; Care must be taken as this does not remove any items from the original array. The array may have been closed over when passed to a function. The array will remain in mem...
#include <stdio.h> #define ARRLEN (10) int main (void) { int n[ ARRLEN ]; /* n is an array of 10 integers */ size_t i, j; /* Use size_t to address memory, that is to index arrays, as its guaranteed to be wide enough to address all of the possible availab...
There are many ways find the location of a value in an array. The following example snippets all assume that the array is one of the following: String[] strings = new String[] { "A", "B", "C" }; int[] ints = new int[] { 1, 2, 3, 4 }; In addition, each one sets...
The <algorithm> header provides a number of useful functions for working with sorted vectors. An important prerequisite for working with sorted vectors is that the stored values are comparable with <. An unsorted vector can be sorted by using the function std::sort(): std::vector<int&...
You can bind to a property on a named element, but the named element must be in scope. <StackPanel> <CheckBox x:Name="MyCheckBox" IsChecked="True" /> <TextBlock Text="{Binding IsChecked, ElementName=MyCheckBox}" /> </StackPanel>
When you need to iterate over the list of jQuery elements. Consider this DOM structure: <div class="container"> <div class="red one">RED 1 Info</div> <div class="red two">RED 2 Info</div> <div class="red three"...
Access the nth element of a list (zero-based): list = [1 .. 10] firstElement = list !! 0 -- 1 Note that !! is a partial function, so certain inputs produce errors: list !! (-1) -- *** Exception: Prelude.!!: negative index list !! 1000 -- *** Exception: Prelude.!!: inde...
It is possible to find the first element of a Stream that matches a condition. For this example, we will find the first Integer whose square is over 50000. IntStream.iterate(1, i -> i + 1) // Generate an infinite stream 1,2,3,4... .filter(i -> (i*i) > 50000) // Filter to find element...
ElementAt will return the item at index n. If n is not within the range of the enumerable, throws an ArgumentOutOfRangeException. int[] numbers = { 1, 2, 3, 4, 5 }; numbers.ElementAt(2); // 3 numbers.ElementAt(10); // throws ArgumentOutOfRangeException ElementAtOrDefault will return the item...
Element operations return a single, specific element from a sequence. ElementAt Returns the element at a specified index in a collection. Method Syntax // ElementAt var strings = new string[] { "zero", "one", "two", "three" }; var str = strings.E...
<rect> represents rectangle, apart from aesthetic properties like stroke and fill, rectangle shall be defined by location and size. As for the location, it is determined by the x and y attributes. The location is relative to the rectangle’s parent. And if you don’t specify the x or y attribut...
<svg> element is the root element, or the canvas as we are drawing charts on it. SVG elements can be nested inside each other, and in this way, SVG shapes can be grouped together, meanwhile, all shapes nested inside an element will be positioned relative to its enclosing element. One thing...
SVG doesn’t currently support automatic line breaks or word wrapping, that’s when comes to rescue. element positions new lines of text in relation to the previous line of text. And by using dx or dy within each of these spans, we can position the word in relation to the word before it. Case: Anno...
Use unpacking to extract the first element and ensure it's the only one: a, = iterable def foo(): yield 1 a, = foo() # a = 1 nums = [1, 2, 3] a, = nums # ValueError: too many values to unpack

Page 6 of 15