-1
I would like to work with the item object but I need to pass values of my activity to the usel someone can explain me?
item[0] = new ColorClothes();
item[0].record = 0;
item[0].color = "blue";
item[0].clothes = "shoes";
For example where there is "blue" I would like to be receiving a value of my activity as it would be possible?
import java.util.*;
public class ColorClothes
{
public int record;
public String color;
public String clothes;
public static void main(String[] args)
{
Initialize();
}
public static void Initialize()
{
ColorClothes item[] = new ColorClothes[4];
item[0] = new ColorClothes();
item[0].record = 0;
item[0].color = "blue";
item[0].clothes = "shoes";
item[1] = new ColorClothes();
item[1].record = 1;
item[1].color = "yellow";
item[1].clothes = "pants";
item[2] = new ColorClothes();
item[2].record = 2;
item[2].color = "red";
item[2].clothes = "boots";
item[3] = new ColorClothes();
item[3].record = 3;
item[3].color = "black";
item[3].clothes = "coat";
System.out.println("Unsorted");
for(int i = 0; i < item.length; i++)
{
System.out.println(item[i].record + " " + item[i].color + " " + item[i].clothes);
}
System.out.println("\nSorted By Color\n");
Arrays.sort(item, new ColorComparator());
for(int i = 0; i < item.length; i++)
{
System.out.println(item[i].record + " " + item[i].color + " " + item[i].clothes);
}
System.out.println("\nSorted By Clothes\n");
Arrays.sort(item, new ClothesComparator());
for(int i = 0; i < item.length; i++)
{
System.out.println(item[i].record + " " + item[i].color + " " + item[i].clothes);
}
}
}
I didn’t quite understand what you want, you have an Object, with 3 attributes, then you create an array of that same object and use it within that object.
– Lucas Queiroz Ribeiro
For example if I have another activity I can use that object ?
– Tiago Coelho
Well, this class is a little bit poorly formed for me, its intention with Initialize()` is to return an array with 4 pre-initialized objects ?
– Lucas Queiroz Ribeiro
yes that’s right
– Tiago Coelho