Java Course

import java.util.ArrayList;

public class MyClass {
public static void main(String[ ] args) {
ArrayList<Integer> numbers = new ArrayList<String>();
numbers.add(1);
numbers.add(2);
numbers.add(3);
numbers.remove(3);
System.out.println(numbers);
Collections.sort(numbers);

System.out.println(Collections.max(numbers));

System.out.println(Collections.min(numbers));

Collections.reverse(numbers);

System.out.println(numbers);

Collections.shuffle(numbers);

System.out.println(numbers);

}
}
//max(Collection colors): Returns the maximum element in c as determined by natural ordering.
//min(Collection c): Returns the minimum element in c as determined by natural ordering.
//reverse(List list): Reverses the sequence in list.
//shuffle(List list): Shuffles (i.e., randomizes) the elements in list.

import java.util.LinkedList;
import java.util.Iterator;
public class MyClass {
public static void main(String[ ] args) {
LinkedList<String> colors = new LinkedList<String>();
colors.add("White");
colors.add("Black");
colors.add("Yellow");
colors.remove("Black");
System.out.println(colors);

for(String s: colors) {
System.out.println(s);

}
Iterator<String> itr = colors.iterator();
while(itr.hasNext()) {
String value = itr.next();
System.out.println(value);
}

}
//initial capacity for the LinkedList can't be specified
//The ArrayList is very similar to a normal array.
//The LinkedList is better for making numerous inserts and deletes.


import java.util.HashMap;
public class MyClass {
public static void main(String[ ] args) {
HashMap<String, Integer> colors= new HashMap<String, Integer>();
colors.put("white", 1);
colors.put("black", 2);
colors.put("yellow", 3);
System.out.println(points.get("white"));
}
}

import java.util.HashSet;

public class MyClass {
public static void main(String[ ] args) {
HashSet<String> colors = new HashSet<String>();
colors.add("A");
colors.add("B");
colors.add("C");
System.out.println(colors);
}
}
//A Set is a collection that cannot contain duplicate elements

 



Dodaj komentarz






Dodaj

© 2013-2024 PRV.pl
Strona została stworzona kreatorem stron w serwisie PRV.pl