Java.util
Talk0this wiki
|
|
java.util is a class in java containing several convinient methods and such. It includes, but is not limited, to some array manipulations tools, a collection framework and date and time tools.
Contents |
Classes
Edit
Arrays
Edit
Arrays is a static class containing helper methods that may be useful when using arrays.
Sort
Edit
java.util.Arrays.sort can be used to sort arrays.
java.util.Arrays.sort(a);
Here a is the name of the array to sort.
Strings or chars will be sorted in alphabetical order, while any number datatypes will be sorted in ascending numerical order.
Scanner
Edit
Scanners can be used to easily collect user input without using BufferedReaders.
import java.util.Scanner; Scanner scan = new Scanner(System.in); String operat = scan.next(); //Change "String" to correct type.
Here used with int:
import java.util.Scanner; Scanner scan = new Scanner(System.in); int operat = scan.nextInt(); //Notice how "scan.next();" changed to "scan.nextInt();"
Collections
Edit
Collections is a static class containing helper methods that may be useful when using a class that implements the Collection interface.
Interfaces
Edit
List
Edit
Map
Edit
Set
Edit
in the mathematical sense Sets have a number of operations that are not present in the Java implementation. fortunately they are easy to simulate.
Union
Edit
Set setA = new HashSet(); Set setB = new HashSet(); //add elements to sets setA.addAll(setB);
Intersection
Edit
Set setA = new HashSet(); Set setB = new HashSet(); //add elements to sets setA.retainAll(setB);
Complement
Edit
Set setA = new HashSet(); Set setB = new HashSet(); //add elements to sets setA.removeAll(setB);