How to use contains() with substring

i have an ArryList which have (name+"\n"+phoneNumber) so I wanna see if the name is containing with the list ? I used this code

HashSet<String> set = new HashSet<String>(ContactsList);
if (set.contains(name))

but how to use substring in contains so I get just the name from it to contain it with the name that I wanna add it to the list

and thanks


Don't add the data in ArrayList as (name+"\n"+phoneNumber), Create a class which 2 attributes name and phoneNumber, then create object of that class set both attributes and add that object in the ArrayList.

This is the right way of doing it and your problem also will be solved.


 ? Understanding Internal implementation of hashmap
 ? Why Error handling is not recommended?
 ? How to filter strings from an array of objects
 ? Ordering with partial explicit and then another order?
 ? How can I force Powershell to return an array when a call only returns one object?
 ? Swift CollectionView set where to scroll
 ? Resource route (edit ) redirecting to 404 page laravel
 ? Laravel 5.3 how to attach file
 ? issue while using extend & yield for Master Layout
 ? How to Login with Google?