arraylist

How do you store three different objects in a list array in Java [closed]

狂风中的少年 提交于 2020-06-23 05:32:30
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I need to create a list array in java that can hold three different objects (Surname, forename, Result) and was wondering how to do that 回答1: The best and also Object Oriented approach is to Create a class with

Getting last row's data in the map

本小妞迷上赌 提交于 2020-06-17 12:57:34
问题 My objective is to create a map. It have reqid , name and lowest status number of a set as a key. Here set refers to rows belonging to a specific Reqid . The value of the map is an Arraylist which consists of all rows as objects of a specific id . public class MapKey { private Integer id; private String name; private Integer status; public MapKey(Integer id, String name,Integer status) { this.id = id; this.name = name; this.status=status; } @Override toString,hashCode,equals public class

Getting last row's data in the map

人走茶凉 提交于 2020-06-17 12:57:31
问题 My objective is to create a map. It have reqid , name and lowest status number of a set as a key. Here set refers to rows belonging to a specific Reqid . The value of the map is an Arraylist which consists of all rows as objects of a specific id . public class MapKey { private Integer id; private String name; private Integer status; public MapKey(Integer id, String name,Integer status) { this.id = id; this.name = name; this.status=status; } @Override toString,hashCode,equals public class

Objects in List have the same value - that of the last element added [duplicate]

£可爱£侵袭症+ 提交于 2020-06-17 04:19:48
问题 This question already has answers here : Why does my ArrayList contain N copies of the last item added to the list? (5 answers) Closed 12 days ago . Hy, I'm a bit new to JAVA, and having a big problem. While I'm adding elements to a List<int[]> the result will be a List full of with the same value. Why JAVA is working like this? Here is the code: // Global variables private static int rows = 20; private static int columns = 30; private static String[][] labirinth = new String[rows][columns];

Objects in List have the same value - that of the last element added [duplicate]

别来无恙 提交于 2020-06-17 04:19:32
问题 This question already has answers here : Why does my ArrayList contain N copies of the last item added to the list? (5 answers) Closed 12 days ago . Hy, I'm a bit new to JAVA, and having a big problem. While I'm adding elements to a List<int[]> the result will be a List full of with the same value. Why JAVA is working like this? Here is the code: // Global variables private static int rows = 20; private static int columns = 30; private static String[][] labirinth = new String[rows][columns];

Second highest number ArrayList

无人久伴 提交于 2020-06-08 12:44:30
问题 So I got this code so far: int secondLargest = list.get(0); int largest = list.get(0); for (int i = 0; i < list.size(); i++) { if(list.get(i) > largest) { secondLargest = largest; largest = list.get(i); if(list.get(i) > secondLargest && list.get(i) != largest) { secondLargest = list.get(i); } } } System.out.print("Second biggest number "); return secondLargest; The problem is that when I use this code (the list is:) list2.add(1); list2.add(2); list2.add(10); list2.add(9); list2.add(8); list2

Removing an element from a List<String[]> not working as expected

瘦欲@ 提交于 2020-06-01 03:42:45
问题 I have an ArrayList of String arrays which is added to like so: List<String[]> data = new ArrayList<>(); data.add(new String[] {var, lex, valor}); When trying to erase one of the String arrays the output is false for some reason. Here's how I remove it: data.remove(new String[] {var, lex, valor}); I've also tried removing using position, the method is as follows: public void eliminarPos(String var, String lex, String valor, Integer ii) { boolean uno = data.remove(ii); System.out.println(uno);

Removing an element from a List<String[]> not working as expected

浪尽此生 提交于 2020-06-01 03:41:31
问题 I have an ArrayList of String arrays which is added to like so: List<String[]> data = new ArrayList<>(); data.add(new String[] {var, lex, valor}); When trying to erase one of the String arrays the output is false for some reason. Here's how I remove it: data.remove(new String[] {var, lex, valor}); I've also tried removing using position, the method is as follows: public void eliminarPos(String var, String lex, String valor, Integer ii) { boolean uno = data.remove(ii); System.out.println(uno);

dataclass copy with field ArrayList - change the ArrayList of the copied class changes the original

假装没事ソ 提交于 2020-05-31 07:02:49
问题 I have a data class like this data class Person(val id: Long = BaseDataContract.BaseData.UNDEFINED_ID.toLong(), ..... val personConsents: ArrayList<PersonConsent> = ArrayList<PersonConsent>()) I have two copies of the object: person = originalPerson.copy() Then I change the elements of personConsents for the object person - I add/delete/edit them. But by some reason I see that the same changes are happening in originalPerson object which I don't want to be. originalPerson is not supposed to

Java 8: merging two Lists containing objects by Id

帅比萌擦擦* 提交于 2020-05-27 04:15:11
问题 I have 2 Lists: // old list List<Employee> oldList = new ArrayList<>(); Employee emp1 = new Employee(); emp1.setPersonalNumber("123"); emp1.setName("old_name1"); emp1.setStatus(Status.OLD); Employee emp2 = new Employee(); emp2.setPersonalNumber("456"); emp2.setName("old_name2"); emp2.setStatus(Status.OLD); oldList.add(emp1); oldList.add(emp2); // new list List<Employee> newList = new ArrayList<>(); Employee newEmp1 = new Employee(); newEmp1.setPersonalNumber("123"); newEmp1.setName("new_name1