public class GetMethodExample {
public static void main(String[] args) {
ArrayList<String> al = new ArrayList<String>();
al.add("pen");
al.add("pencil");
al.add("ink");
al.add("notebook");
al.add("book");
al.add("books");
al.add("paper");
al.add("white board");
System.out.println("First element of the ArrayList: "+al.get(0));
System.out.println("Third element of the ArrayList: "+al.get(2));
System.out.println("Sixth element of the ArrayList: "+al.get(5));
System.out.println("Fourth element of the ArrayList: "+al.get(3));
}
}
public class test {
public static void main(String[] args) {
// create an empty array list with an initial capacity
ArrayList<String> color_list = new ArrayList<String>(5);
// use add() method to add values in the list
color_list.add("White");
color_list.add("Black");
color_list.add("Red");
color_list.add("White");
color_list.add("Yellow");
// Print out the colors in the ArrayList.
for (int i = 0; i < 5; i++)
{
System.out.println(color_list.get(i).toString());
}
}
}
public class ArrayListDemo {
public static void main(String[] args) {
// create an empty array list with an initial capacity
ArrayList<Integer> arrlist = new ArrayList<Integer>(5);
// use add() method to add elements in the list
arrlist.add(15);
arrlist.add(22);
arrlist.add(30);
arrlist.add(40);
// let us print all the elements available in list
for (Integer number : arrlist) {
System.out.println("Number = " + number);
}
// retrieves element at 4th postion
int retval = arrlist.get(3);
System.out.println("Retrieved element is = " + retval);
}
}
public class ArrayListExample
{
public static void main(String[] args)
{
ArrayList<String> list = new ArrayList<>(Arrays.asList("alex", "brian", "charles", "dough"));
String firstName = list.get(0); //alex
String secondName = list.get(1); //brian
System.out.println(firstName);
System.out.println(secondName);
}
}
public class GFG {
public static void main(String[] args)
{
// creating an Empty Integer ArrayList
ArrayList<Integer> arr = new ArrayList<Integer>(4);
// using add() to initialize values
// [10, 20, 30, 40]
arr.add(10);
arr.add(20);
arr.add(30);
arr.add(40);
System.out.println("List: " + arr);
// element at index 2
int element = arr.get(2);
System.out.println("the element at index 2 is " + element);
}
}
private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
final Rect r = mRectTemp;
final ArrayList<DropTarget> dropTargets = mDropTargets;
final int count = dropTargets.size();
for (int i=count-1; i>=0; i--) {
DropTarget target = dropTargets.get(i);
if (!target.isDropEnabled())
continue;
target.getHitRectRelativeToDragLayer(r);
mDragObject.x = x;
mDragObject.y = y;
if (r.contains(x, y)) {
dropCoordinates[0] = x;
dropCoordinates[1] = y;
mLauncher.getDragLayer().mapCoordInSelfToDescendent((View) target, dropCoordinates);
return target;
}
}
return null;
}
public void encodeDecodeShortListWithTwoByteArraysWithElementsLength56() {
byte[] value1 = new byte[26];
byte[] value2 = new byte[28];
byte[] element1 = RLP.encodeElement(value1);
byte[] element2 = RLP.encodeElement(value2);
byte[] encoded = RLP.encodeList(element1, element2);
Assert.assertNotNull(encoded);
Assert.assertEquals(1 + 1 + 1 + 26 + 1 + 28, encoded.length);
Assert.assertEquals((byte)(247 + 1), encoded[0]);
Assert.assertEquals((byte)(56), encoded[1]);
ArrayList<RLPElement> list = RLP.decode2(encoded);
Assert.assertNotNull(list);
Assert.assertEquals(1, list.size());
RLPList list2 = (RLPList) list.get(0);
Assert.assertNotNull(list2);
Assert.assertEquals(2, list2.size());
Assert.assertArrayEquals(value1, list2.get(0).getRLPData());
Assert.assertArrayEquals(value2, list2.get(1).getRLPData());
}
static void updateItemsInDatabaseHelper(Context context, final ArrayList<ContentValues> valuesList,
final ArrayList<ItemInfo> items, final String callingFunction) {
final ContentResolver cr = context.getContentResolver();
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
Runnable r = new Runnable() {
public void run() {
ArrayList<ContentProviderOperation> ops =
new ArrayList<ContentProviderOperation>();
int count = items.size();
for (int i = 0; i < count; i++) {
ItemInfo item = items.get(i);
final long itemId = item.id;
final Uri uri = LauncherSettings.Favorites.getContentUri(itemId);
ContentValues values = valuesList.get(i);
ops.add(ContentProviderOperation.newUpdate(uri).withValues(values).build());
updateItemArrays(item, itemId, stackTrace);
}
try {
cr.applyBatch(LauncherProvider.AUTHORITY, ops);
} catch (Exception e) {
e.printStackTrace();
}
}
};
runOnWorkerThread(r);
}
private void prepareMonoPixelMap() {
int[] row_cache = null;
final int line = rgbData.length;
final int column = rgbData[0].length;
ArrayList<Point> al = new ArrayList<Point>();
// Point first = null;
for (int y = 0; y < line; y++) {
row_cache = rgbData[y];
for (int x = 0; x < column; x++)
if (row_cache[x] == monoColor)
al.add(new Point(x, y));
}
monoXY_Map = new int[2][al.size()];
for (int i = 0; i < al.size(); i++) {
Point p = (Point) al.get(i);
monoXY_Map[0][i] = (int) p.getX();
monoXY_Map[1][i] = (int) p.getY();
}
rgbData = null;
}
public boolean isFixedView(View v) {
int i;
ArrayList<FixedViewInfo> where = this.mHeaderViewInfos;
int len = where.size();
for (i = 0; i < len; i++) {
if (((FixedViewInfo) where.get(i)).view == v) {
return true;
}
}
where = this.mFooterViewInfos;
len = where.size();
for (i = 0; i < len; i++) {
if (((FixedViewInfo) where.get(i)).view == v) {
return true;
}
}
return false;
}