java list to set
Set<Foo> foo = new HashSet<Foo>(myList);
java list to set
Set<Foo> foo = new HashSet<Foo>(myList);
selection sort in java
public static void SelectionSort(int[] arr)
{
int small;
for (int i = 0; i <arr.length - 1; i++)
{
small = i;
for (int j = i + 1; j < arr.length; j++)
{
//if current position is less than previous smallest
if (arr[j] < arr[small])
{
small = j;
//swap values
int temp = arr[i];
arr[i] = arr[small];
arr[small] = temp;
}
}
}
}
how to sort collection in java
// Use Collections.sort()
import java.util.*;
ArrayList<String> al = new ArrayList<String>();
al.add("teach");
al.add("sleep");
al.add("geek");
Collections.sort(al);//just pass any collection object reference
System.out.println(al);//output :- [geek,sleep,teach]
or
/*
ArrayList<Integer> intal = new ArrayList<Integer>();
al.add(4);
al.add(8);
al.add(2);
Collections.sort(intal);
System.out.println(intal);//output :- [2,4,8]
*/
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us