Answers for "array and arraylist in java"

21

Difference between Array vs ArrayList

Arrays are fixed size
ArrayList's size auotomatically adjusted
Arrays can hold primitives and object
ArrayList can hold only objects
Arrays can be multi dimensional
ArrayList cannot be multi-dimentional
Array is a build in data structure
ArrayList is implementing class of List interface in Collection framework
Posted by: Guest on November-28-2020
0

aaraylist java

List<String> list = new ArrayList<String>();
		list.add("a");
		list.add("b");
		list.add("c");
		list.add("d");
		list.add("e");
		list.add("f");

		//Die Liste zufällig durchmischen
		Collections.shuffle(list);
		System.out.println(list);

		//Die Liste sortieren
		Collections.sort(list);
		System.out.println(list);

		Collections.rotate(list, -1);
		System.out.println(list);

		//Hier geben wir nur einen Teil (sub) der Liste aus
		List<String> sub = list.subList(2, 5);
		System.out.println(sub);
		Collections.reverse(sub);
		System.out.println(sub);

		//Hier können wir die Liste manipulieren
		ListIterator<String> it = list.listIterator();
		while(it.hasNext()){
			String str = it.next();
			if(str.equals("d"))
				it.set("z");
		}
		while(it.hasPrevious())
			System.out.print(it.previous());
Posted by: Guest on October-30-2021

Code answers related to "array and arraylist in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language