taskfutureForkjoinpool.submit (Task); Try{System.out.println (Result.get ()); } Catch(Exception e) {System.out.println (e); } }}Requirements such as summation and sequencing can be achieved through forkjoin thinking, but in practice it is necessary to perform the required performance tests to confirm the magnitude of the performance increase.In the above code, you define an additive task, in the compute method, to determine whether the current value is less than a threshold value, if
1.fill Method
The Fill method is primarily used to populate arrays, and here we give the simplest type of int (the other types).
Look at arrays's fill source.
Sample code:
Java Code
Publicstaticvoidmain (string[] args) {
INTA[]=NEWINT[5];
Fill filled Array
Arrays.fill (a,1);
for (inti=0;i
System.out.println (A[i]);
}
populate part of the array source code:
Example:
New Array in Java:String[] s;//is defined without the need to set the size S = new string[5];//to set the size of the array when allocating space for arraylist,arraylistin the case of Java SE 1.5, without generics, by referencing the type object to implement the "arbitrariness" of the arguments, the disadvantage of "arbitrariness" is to make explicit coercion of type conversions, and this conversion is required by the developer for the actual paramete
Use the Java runnable interface to simulate parallel programs for multi-window (thread) Sales of the same type of tickets, the same type of runnable
Refer to this blog post (http://blog.csdn.net/liutengteng130/article/details/20036517), where the use of the thread and runnable interface to achieve multi-window ticket simulation problem.
As for the features of the runnable interface implementation method-t
Refer to this blog post (http://blog.csdn.net/liutengteng130/article/details/20036517), where you can use the thread and runnable interface to implement the ticketing multi-window simulation problem.Runnable interface implementation of the characteristics of the method--multi-threaded error-Free modification class public variable value problem, feel very valuable, the source code to make a comment, take to analyze and share with you:Class ThreadTest implements runnable{ private int ticket =1
Content: In Java, using callable to perform thread calculations with return results, using the future to represent the results of asynchronous computations, calculate the sum of long sums in different ranges separately, and similar ideas can be used for reference to places that require a lot of computation. public class Sums {public static class Sum implements CallableJava uses callable and future to compute sums in
Sort java string arrays by size and java string Arrays
If two strings are compared directly, The packet: the operator> is undefined for The argument type (s) java. lang. String, java. lang. String is incorrect.
To compare the size
Java Learning (8), static method, Arrays class, two-dimensional array, and arrays two-dimensional array
I. Static Methods
Static Methods belong to the class and can be called directly by class name. Method Name.
Static Method Declaration
Access modifier static type method name (parameter list)
{
// Method body
}
The role of the method: a program is divided into s
Java learning notes-Arrays, learning notes-arraysCommon Arrays Methods
Arrays. toString (int [] a) method -------> the return type is String, which can be used to generate printable representation of the array. This avoids reading array values cyclically for printing.
Arrays
The Arrays class is a tool class provided in Java, in the Java.util package. The class contains methods for manipulating arrays directly, such as sorting, searching, and so on (for classes and methods), which are explained in detail in a later section.Common methods in Arrays:1. SortingSyntax: arrays.sort (array name);
Array, which is a combination of multiple data types of the same type.The use of arrays includes declaring arrays, creating arrays, assigning values.Declaration of one-dimensional array, such as: float[] A; or float a[]Declarations of two-dimensional arrays, such as: float[] [] A or float a[[]The array declaration is n
This class implements:Output a row of array data, according to the input subscript, the following position is the end, the original array is divided into two sets of sub-arrays.and swaps the positions of two sub-arrays, keeping the ordinal number of the elements in the subarray unchanged.For example: The original array is 7,9,8,5,3,2 the following 3 is the split point, divided into sub-array one: 7,9,8,5. and sub-array two: 3,2.The result after the sw
Two-dimensional arraysThe Java language provides syntax to support multidimensional arrays. But if you look at the operating mechanism at the bottom of the array-there are no multidimensional arrays.The array type in Java is a reference type, so the array variable is actually a reference, which points to the real array memory, the type of the array element can al
, Arry2)); Filling fill Arrays.fill (Arry2, "Guangzhou"); System.out.println ("Arry2 value after padding:" +arrays.tostring (Arry2)); Query BinarySearch The premise is that the array has been sorted before you can use System.out.println ("Chongqing in arry1 Position:" +arrays.binarysearch (Arry1, "Chongqing")); }}Operation Result:Arry2 is: [Beijing, Shanghai, Chongqing, Shenzhen]arry1 and Arry2 are equal: True after sorting the value of the arry1: [Shanghai, Beijing, Shenzhen, C
. The corresponding elements in the array can be checked directly according to the result of the operation as a corner mark. This way: called the look-up table method. */ Public Static voidTohex_1 (intnum) { //define a corresponding relational table Char[] CHS = {' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ', ' C ', ' D ', ' E ', ' F '}; for(intx=0;x) { inttemp = num 15; System.out.print (Chs[temp]); Num= num >>>4; } } Pu
The use of two-dimensional arrays in Java (indefinite long two-dimensional arrays), that is, the array lengths of each second dimension are different.
1 Code as follows:
Package com.demo.test; public class Test {public Test () {//TODO auto-generated constructor stub} public static void Main (string[] args
{//TODO auto-generated method Stub int []
Array:#include Dynamic arrays:#include Difference: Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. Java Programmers learn C + + arrays and dynamic arrays
In Java, byte arrays and long arrays are converted to each other.
The byteandlongarraytest code is as follows:
Package com. array. test;
Import java. Io. ioexception;
/**
* @ Version 1.0
* @ Author wangwei
* @ Created on 2008-10-17
*/
Public class byteandlongarraytest {
/**
* Convert a long array to a
)); //change the value of the A2 array from subscript 1 to subscript 3 to 1Arrays.fill (A2, 1, 3, 1); System.out.println (The value of the output A2 array is: "+arrays.tostring (A2)); }}The output is:The A1 array is sorted by: [1, 2, 3, 4]Find the value of 4 in the A1 array subscript: 3Find the A1 array from subscript 1 to subscript 3 end to see if there is a value of 3 2The values of the A3 array are: [1, 2, 3, 4, 0]The A4 array value is: [3]See if the A1 array and the A2 array are the same: fa
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.