Why can't I get a value from an ArrayList?

Why can't I get a value from an ArrayList?

By : Glen Greenwood
Date : November 19 2020, 03:59 PM
will be helpful for those in need This is your code, completely working what you want. Read comments for changes/addition
code :
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    static Scanner scanner = new Scanner(System.in);

    public static List<Integer> pinNumbers = new ArrayList<Integer>();

    public static void main(String[] args) {
        System.out.println("Insert your first pin number");
        int num1 = scanner.nextInt();
        System.out.println("Insert your second pin number");
        int num2 = scanner.nextInt();
        System.out.println("Insert your third pin number");
        int num3 = scanner.nextInt();
        System.out.println("Insert your fourth pin number");
        int num4 = scanner.nextInt();
        System.out.println("Starting the crack!");

        int currentChar = 0;
        int currentNum = 0;

        String pin = "" + pinNumbers.get(0) + pinNumbers.get(1) + pinNumbers.get(2) + pinNumbers.get(3);
        List<Integer> crackedPin = new ArrayList<Integer>();
        String pinCracked = ""; //Changed

        while(!pinCracked.equals(pin)){ //Changed Equating reference before, always true
            if(currentChar<4){ //Changed Out of bound
                    pinCracked+=currentNum; //Added, Change the string instead
        System.out.println(pinCracked); //Changed


Share : facebook icon twitter icon
Why does ArrayList<ArrayList<?>> list = new ArrayList<ArrayList<String>>() not compile?

Why does ArrayList<ArrayList<?>> list = new ArrayList<ArrayList<String>>() not compile?

By : zar ni oo
Date : March 29 2020, 07:55 AM
Hope this helps Why does this code compile , In
code :
final ArrayList<?> dp1 = new ArrayList<String>();
final ArrayList<ArrayList<?>> dp2 = new ArrayList<ArrayList<String>>();
Creating an ArrayList of ArrayList having one additional element compared to another ArrayList of ArrayList

Creating an ArrayList of ArrayList having one additional element compared to another ArrayList of ArrayList

By : wendel
Date : March 29 2020, 07:55 AM
help you fix your problem I have an ArrayList of ArrayList (alal) and an ArrayList(al). I want to insert al to alal, but I want alal.get(0) to contain everything al has plus the element 100 added. I thought the easiest way to do this, is to first do , Wrap your list into a new ArrayList when adding, thus cloning it:
code :
alal.add(new ArrayList<>(al));
class Person {
    String name = "";

    public String getName() {
        return this.name;

    public void setName(String otherName) {
        this.name = otherName;

    public String toString() {
        return "Person[name=" + this.name + ']';
Person user = new Person();

List<Person> persons = new ArrayList<>();

List<List<Person>> personGroups = new ArrayList<>();
personGroups.add(new ArrayList<>(persons));
persons: [Person[name=saltandwater]]
personGroups: [[Person[name=saltandwater]]]
user.setName("Mr. Yetti");
persons: [Person[name=Mr. Yetti]]
personGroups: [[Person[name=Mr. Yetti]]]
how to retrieve Firebase json ArrayList inside Arraylist data and store it in Arraylist for display in Textview later

how to retrieve Firebase json ArrayList inside Arraylist data and store it in Arraylist for display in Textview later

By : Mario Field
Date : March 29 2020, 07:55 AM
this one helps. You are referencing the node purchasebill, and then you are looping inside the direct children of purchasebill which are gameworld and datamination.
To solve your problem, you can add a reference to child datamination thus it won't loop inside gameworld, so you can do the following:
code :
myRef.child("datamination").addValueEventListener(new ValueEventListener() {
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            billlistHelper = dataSnapshot.getValue(BilllistHelper.class);
            assert billlistHelper != null;
            for (DataSnapshot dd : dataSnapshot.child("datedata").getChildren(){
                dateDataHelper = dd.getValue(DateDataHelper.class);



Cannot convert ArrayList<ArrayList<Integer>> to ArrayList<ArrayList<Object>>

Cannot convert ArrayList<ArrayList<Integer>> to ArrayList<ArrayList<Object>>

By : user3149890
Date : March 29 2020, 07:55 AM
wish of those help There are 2 solutions:
1.Use generic (and btw should use List instead of ArrayList)
code :
public static <T> List<List<T>> foo(List<List<T>> parameter) {
    //do something

public void test() {
    List<List<Integer>> parameter;
    //do something with the parameter
    List<List<Integer>> product = foo(parameter);
public static List<? extends List<? extends Object>> foo(List<? extends List<? extends Object>> parameter) {
    //do something

public void test() {
    List<List<Integer>> parameter = new ArrayList<>();
    //do something with the parameter
Java arraylist of arraylist - create a multi dimensional arraylist with a class object

Java arraylist of arraylist - create a multi dimensional arraylist with a class object

By : doan dinh Tuan
Date : March 29 2020, 07:55 AM
Hope this helps I'm looking to create an arraylist of arraylist. , Instead of:
Related Posts Related Posts :
  • Stream corrupted exception - invalid code type AC [java]
  • Routing Sysout values to JTextArea
  • GWT RPC serialization for Dynamic Host Page
  • Best Approch of Returning Value from 'getter' Method
  • Understanding xml schemalocation
  • Checking if a PDF is PDF/A 1-a format or not using PDFBOX in java
  • Difference Between Variable and Identifier
  • How to compute two aggregate functions with Java streams?
  • Parse the value of the json to baseadapter in android?
  • JavaFX animation on raspberry pi
  • Solve "unchecked warning" in Java avoiding @suppressWarnings
  • How to specify a new name for a file while moving it to another directory in Java?
  • Popup window not showing up with spinner item selection?
  • how to iterate through json objects in java
  • Caused by: java.lang.NoClassDefFoundError: org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor
  • Getting NoClassDefFoundError while running PMD task from Gradle
  • Matlab drag and drop file from windows explorer to figure (gui)
  • How does scala's actor model make use of C threads and native system threads?
  • Store java.util.Date as key in a Map based on reference equality instead of "value" equality
  • Error when logging into FTP from AsyncTask class using org.apache.commons.net.ftp.FTPClient
  • creating unique index in mongoDB
  • hibernate Query to find record based on substring
  • How many strings are in jvm string pool intern
  • Unable to initialize native-platform. on Jenkins
  • How to create a list of dummy files in Java?
  • Docker: Which approach is better? WAR embedded in image or base image + war?
  • java.lang.InternalError: CallerSensitive annotation expected at frame 1
  • How to write a method to read JSON files of different structures and return different POJO objects in Java?
  • Reference to Classes in Java
  • Unable to call function via companion object
  • REST: convert XML content passed with POST to a java object, attribute inside the element
  • Device not receive message from GCM
  • How to increase Openfire concurrent connection limit?
  • Android send custom parameter on AsyncTask
  • GWT - Get dom element's value from another page
  • How can i initialize an array in Java?
  • Is it possible to increase a java process's(when is running) size?
  • Getting Node Address instead of Value in Binary Search Tree
  • PdfByteContent not adding in iText pdf
  • Spring JpaRepository: delete() with subsequent save() in the same transaction
  • producer-consumer using arraydeque working only in breakpoint
  • Adding a JPanel to another JPanel
  • Comparison with operator ==, how does it work?
  • Error buildling with maven for openshift
  • What is the java equivilant to MySQL's smallint
  • proxy trouble on eclipse with https
  • Spring-Jdbc Template and Prepared statement
  • Mule - exception in Outbound endpoint Message payload is of type: byte[]
  • Modify package names for java classes generated from wsdl
  • How to download multiple images and have one progressBar using AsynTask (Android)
  • Implementing Service Provider, IdP and user in java with SAML (POC)
  • Why does my scanner repeat?
  • Can I forget ResultSetFuture in Cassandra java driver without facing memory leak?
  • XML to JAXB binding having nested elements?
  • Java: ToString() prints the same hashcode each time
  • Why am I getting a thread exception in my graphics program?
  • Can we read 4th byte from hexadecimal value?
  • How to create watermark in image just like Google maps watermarks
  • how come Thread class called inside another class?
  • AssertionError: Unexpected schema version 0: Unexpected schema version 0
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org