work on lab5(4)

master
Caleb Fontenot 2023-03-07 13:25:42 +07:00
parent 397f12dc2a
commit 2c998b085e
1 changed files with 34 additions and 0 deletions

@ -5,6 +5,8 @@
package com.calebfontenot.lab5_calebfontenot;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
/**
@ -42,8 +44,40 @@ public class Person {
return "Person{" + "name=" + name + '}';
}
public static void checkArrayList() {
Integer[] arr = {3, 1, 2, 3, 6, 3, 4, 6, 3};
ArrayList<Integer> list =new ArrayList<Integer>(Arrays.asList(arr));
System.out.println(list);
Object[] arr3 = list.toArray();
for (int i = 0; i < 3; ++i) {
System.out.print(arr3[i] + " ");
}
System.out.println("max is " + Collections.max(list));
System.out.println();
}
public static void ArrayListGeneric()
public static ArrayList<Integer> removeDuplicate(ArrayList<Integer> list) {
//list.contains();
//list.remove();
System.out.println(list);
ArrayList<Integer> newList = new ArrayList<>();
for (int i = 0; i < list.size(); ++i) {
if (!newList.contains(list.get(i))) {
newList.add(list.get(i));
}
}
return newList;
}
public static void main(String[] args)
{
Integer[] arr = {3, 1, 2, 3, 6, 3, 4, 6, 3};
ArrayList<Integer> list2 =new ArrayList<>(Arrays.asList(arr));
System.out.println(removeDuplicate(list2));
ArrayList list = new ArrayList();
list.add(new Person("John Wayne", "123 Sunny Dr. Santa Barabara, 90611", "922-337-3231", "jw@gmail.com"));
list.add(new Date());