Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
23 views

Java FD - Lists

The document provides an overview of Java List operations and methods. It discusses how Lists can be initialized and elements added, removed, accessed, and sorted. It also describes common List methods like size(), add(), remove(), get(), and contains() and how they work. The document compares Lists to arrays and highlights some key differences in how elements are accessed and manipulated in each.

Uploaded by

Bernal Familia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Java FD - Lists

The document provides an overview of Java List operations and methods. It discusses how Lists can be initialized and elements added, removed, accessed, and sorted. It also describes common List methods like size(), add(), remove(), get(), and contains() and how they work. The document compares Lists to arrays and highlights some key differences in how elements are accessed and manipulated in each.

Uploaded by

Bernal Familia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

LISTS<ELEMENT> - OVERVIEW

List<String> names = new ArrayList<>(); // <String> - moje da e Integer,Double..

names.add("Kriss");
names.add("George");
names.add("Putin");
names.remove…

System.out.println(names); // [Kriss, George, Putin]

na Array se izchislqva duljinata primerno names.length a na List e names.size()

na Array za da vzemesh element/index e primerno names[i, 1, 0..] a na Lists e


names.get(I, 0, 1..) no get() samo vzima stoinosta a set() q zadava..

primerno ako iskame na index 0 da zadadem stoinost shte e taka:

Lists – names.set(0, “Shumi”);

Arrays – names[0] = “Shumi”;

Ne promenqme vida na lista samo elementa mu

Lista raboti po burzo ot masiva zashtoto zadelq predvaritelno dvoino poveche


mqsto za rabota !! 

List<Integer> numbers = new ArrayList<>();

numbers.add(20);
numbers.add(30);
numbers.add(100);
numbers.add(30);
numbers.add(30);

System.out.println(numbers); // [20, 30, 100, 30, 30]

numbers.remove(Integer.valueOf(30));

System.out.println(numbers); // [20, 100, 30, 30]

Integer.valueOf – triene po stoinost moje I String.valueOf I etc… no tova iztriva


purvoto chislo ot nachaloto 0 dokuto stigne chisloto I trie samo nego ne
vsichkite chisla koito sa 30 primerno a purvoto DO KOETO STIGNE 
get opciqta moje da se polzva taka:
List<Integer> numbers = new ArrayList<>();

numbers.add(20);
numbers.add(30);
numbers.add(100);

int firstNumber = numbers.get(0); // 20

Drugi operacii

Provides operations to add / insert / remove / find elements:

size() – number of elements in the List<E>

add(element) – adds an element to the List<E>

add(index, element) – inserts an element to given position

remove(element) – removes an element (returns true / false)

remove(index) – removes element at index

contains(element) – determines whether an element is in the list

set(index, item) – replaces the element at the given index

Sort method for lists..


Collections.sort(name);

Sortira po red ot 1…10 ili po azbuka ot a…z

A za da gi oburnem v obraten red s posledovatelnost purvo:

Collections.sort(name);

Collections.reverse(name);
listName.contains() e komanda koqto moje da izpolzva primerno v while loop I
dokuto ne iztrie vsichki takiva chisla ne spira kakto na primera

while (finalNumbers.contains(Integer.parseInt(input[1]))) {
finalNumbers.remove(Integer.valueOf(input[1]));
}

String.join…masiv

Shitty way to swap strings in list bez da znaesh poziciite

if (powers[0].equals("Swap")) {

String temp = powers[1];


String tempTwo = powers[2];

int position = 0;
int positionTwo = 0;
for (int i = 0; i < mineDeck.size(); i++) {

if (mineDeck.get(i).equals(temp)) {
position = i; // namirash poziciite kudeto se namirat
}
if (mineDeck.get(i).equals(tempTwo)) {
positionTwo = i; // namirash poziciite kudeto se namirat

}
}

mineDeck.set(positionTwo, powers[1]); // I sled tva gi obrustash/swap


mineDeck.set(position, powers[2]);
}

You might also like