arraylist

How to animate a marker through an ArrayList of LatLng points?

放肆的年华 提交于 2019-12-21 05:24:22
问题 I am using Google Maps API V2 to get the location of the current user and am recording his route by using the onLocationChanged listener. While the user records their route I save all the LatLngs detected at each location change in an arraylist. When the user stops recording their route I place a marker at the first point in the arraylist. My problem now is that I wish to animate the marker through all the points in the arraylist. Can someone please tell me how can I do this? Things to note

Custom pagination by array list

倾然丶 夕夏残阳落幕 提交于 2019-12-21 04:46:14
问题 I want to create, in java code, a custom pagination by an array list import org.springframework.data.domain.Sort; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Sort.Direction; ... int page = 0; int count = 8; String sortOrder = "desc"; String sortBy = "id"; Sort sort = new Sort(Direction.fromString(sortOrder), sortBy); PageRequest pageable = new

Should I use a Listener or Observer?

霸气de小男生 提交于 2019-12-21 03:39:28
问题 I have a dropdown box in my GUI which shows the contents of an ArrayList in another class. New objects can be added to the ArrayList elsewhere in the GUI, so I need to know when it is updated, so I can refresh the dropdown menu. From what I can gather, my two options are to extend the ArrayList class to allow me to add my own changeListener to it, or to make the class which contains the ArrayList in question extend observable. Which would be a more appropriate solution? 回答1: The two solutions

How to convert ArrayList to String[] in java, Arraylist contains VO objects

爷,独闯天下 提交于 2019-12-21 03:29:18
问题 Please help me to convert ArrayList to String[]. The ArrayList contains values of type Object(VO). For example, The problem is that I need to convert a country List to String Array, sort it and then put it in a list. However I am getting a ClassCastException. 回答1: String [] countriesArray = countryList.toArray(new String[countryList.size()]); I have assumed that your country List name is countryList . So to convert ArrayList of any class into array use following code. Convert T into the class

How to compare two huge List<String> in Java?

核能气质少年 提交于 2019-12-21 02:44:15
问题 My application generates 2 big lists (up to 3.5mill string records). I need the best and fastest way to compare it. Currently I am doing it like this: List list1 = ListUtils.subtract(sourceDbResults, hiveResults); List list2 = ListUtils.subtract(hiveResults, sourceDbResults); But this method is really expensive on memory as i see from jconsole and sometimes process even stack on it. Any good solutions or ideas? Element positions/order in the list are always the same, so I dont need to deal

Java面试题库及答案解析

核能气质少年 提交于 2019-12-20 23:48:06
1、面向对象编程(OOP)有哪些优点? 代码开发模块化,更易维护和修改。 代码复用。 增强代码的可靠性和灵活性。 增加代码的可理解性。 2、面向对象编程有哪些特性? 封装、继承、多态、抽象 封装 封装给对象提供了隐藏内部特性和行为的能力。对象提供一些能被其他对象访问的方法来改变它内部的数据。在Java当中,有3种修饰符:public,private和protected。每一种修饰符给其他的位于同一个包或者不同包下的对象赋予了不同的访问权限。 下面列出了使用封装的好处: 通过隐藏对象的属性来保护对象内部的状态。 提高了代码的可用性和可维护性,因为对象的行为可以被单独的改变或者是扩展。 禁止对象之间的不良交互提高模块化。 继承 继承给对象提供了从基类获取字段和方法的能力。继承提供了代码的重用,也可以在不修改类的情况下给现存的类添加新特性。 多态 多态是编程语言给不同的底层数据类型做相同的接口展示的一种能力。一个多态类型上的操作可以应用到其他类型的值上面。 抽象 抽象是把想法从具体的实例中分离出来的步骤,因此,要根据他们的功能而不是实现细节来创建类。Java支持创建只暴露接口而不包含方法实现的抽象的类。这种抽象技术的主要目的是把类的行为和实现细节分离开。 3、什么是Java虚拟机?为什么Java被称作是“平台无关的编程语言”? Java虚拟机是一个可以执行Java字节码的虚拟机进程

史上最全Java集合面试题

╄→尐↘猪︶ㄣ 提交于 2019-12-20 22:37:30
1、你所知道的集合类都有哪些?主要方法? 最常用的集合类是 List 和 Map。 List 的具体实现包括 ArrayList 和 Vector,它们是可变 大小的列表,比较适合构建、存储和操作任何类型对象的元素列表。 List 适用于按数值索 引访问元素的情形。 Map 提供了一个更通用的元素存储方法。 Map 集合类用于存储元素对(称作"键"和"值"), 其中每个键映射到一个值。 ArrayList/Vector List Collection HashSet/TreeSet Set HashTable Treemap/HashMap 我记的不是方法名,而是思想,我知道它们都有增删改查的方法,但这些方法的具体名称, 我记得不是很清楚,对于 set,大概的方法是 add,remove, contains;对于 map,大概的方 法就是 put,remove,contains 等,因为,我只要在 eclispe 下按点操作符,很自然的这些方 法就出来了。我记住的一些思想就是 List 类会有 get(int index)这样的方法,因为它可以按 顺序取元素,而 set 类中没有 get(int index)这样的方法。List 和 set 都可以迭代出所有元素, 迭代时先要得到一个 iterator 对象,所以,set 和 list 类都有一个 iterator 方法,用于返回那

java-ArrayList集合

南笙酒味 提交于 2019-12-20 20:37:58
一.集合的创建 导包:import java.util.ArrayList; 创建对象:ArrayList<要存储元素的数据类型> 变量名 = new ArrayList<要存储元素的数据类型>(); 集合中存储的元素,只能为<>括号中指定的数据类型元素; <要存储元素的数据类型>中的数据类型必须是引用数据类型,不能是基本数据类型; 基本数据类型 对应的引用数据类型表示形式 byte Byte short Short I nt Integer long Long float Float double Double char Character boolean Boolean //存储String类型的元素 ArrayList<String> list = new ArrayList<String>(); //存储int类型的数据 ArrayList<Integer> list = new ArrayList<Integer>(); //存储Phone类型的数据 ArrayList<Phone> list = new ArrayList<Phone>(); 二.集合中常用方法 boolean add(Object obj): 将指定元素obj追加到集合的末尾 Object get(int index): 返回集合中指定位置上的元素 int size(): 返回集合中的元素个数

getting all static variables in a class into array/list

笑着哭i 提交于 2019-12-20 18:23:20
问题 Bit of a wierd requirement. public class DummyClass{ public static final DummyClass var1; public static final DummyClass var2; public static final DummyClass var3; . . . public static final DummyClass var100; } Now from outside of this class can we pool this var's into a single array or list, so that I can iterate over them? Like if i do something like List<DummyClass> dummyList = *some op*; //I want value of some op. I should be able to access var1...var100 回答1: You could use reflection:

How to remove duplicates from a list based on a custom java object not a primitive type?

旧街凉风 提交于 2019-12-20 17:43:14
问题 Before I post this question, I found somehow similar question posted here. But the answer was based on a String. However, I have a different situation here. I am not trying to remove String but another object called AwardYearSource. This class has an int attribute called year. So I want to remove duplicates based on the year. i.e if there is year 2010 mentioned more than once, I want to remove that AwardYearSource object. How can I do that? 回答1: The simplest way to remove elements based on a